Angular *ngIf长度不起作用,但显示出良好的价值
在我的模板中:Angular *ngIf长度不起作用,但显示出良好的价值,angular,Angular,在我的模板中: {{(services | async)?.length}} 返回“3”-数组中正确的项数。 但当我使用*ngIf时: <ion-text *ngIf="(services | async)?.length == 3">{{(services | async)?.length}}</ion-text> {{(服务|异步)?.length} 不显示任何内容。我不明白为什么*ngIf返回false?这是因为在observable发出属性长度等于3的第一个
{{(services | async)?.length}}
返回“3”-数组中正确的项数。
但当我使用*ngIf时:
<ion-text *ngIf="(services | async)?.length == 3">{{(services | async)?.length}}</ion-text>
{{(服务|异步)?.length}
不显示任何内容。我不明白为什么*ngIf返回false?这是因为在observable发出属性长度等于3的第一个值之前没有执行第二个订阅,所以条件变为true,第二个表达式得到计算,请尝试分配(服务|异步)?将长度设置为另一个范围更大的变量,然后在测试和显示中使用它
<ng-container *ngIf="(services | async)?.length as length">
<ion-text *ngIf=" length=== 3">{{length}}</ion-text>
</ng-container>
{{length}}
错误:“未捕获(承诺中):语法错误:在.operator之后缺少名称
发布与服务相关的代码`collection$(path:string,query?{返回this.afs.collection(path,query).snapshotChanges().pipe(map(actions=>{返回actions.map(a=>{const data=a.payload.doc.data();const id=a.payload.doc.id;返回{id,…data};});})`