我试图从api收到的离子应用中实现产品类别。但同时实现相同的我碰到下面的错误离子ng-if产生错误 - 离子3
Error: Template parse errors:
Can't bind to 'ng-if' since it isn't a known property of 'div'."
这里是代码:
<div class="width50" *ngFor="let object of dataList">
<div *ng-if= "{{object?.categories[0]?.slug}} == single">
<img src="{{object.images[0].src}}" width="150" (click)="navigateToPage(object.id)" />
</div>
</div>
当我打印的{{object?.categories[0]?.slug}}
代码工作正常,并返回一个值。
使用* ngif over * ng-if也似乎不起作用它显示以下错误。
`Template parse errors:
TypeError: key[0] is undefined ("
<ion-content padding>
<div class="width50" *ngFor="let object of dataList">
<div [ERROR ->]*ngIf= "{{object?.categories[0]?.slug}} == single">
<img src="{{object.images[0].src}}" width="15"): ng:///AppModule/[email protected]:9
Can't bind to '*ngIf' since it isn't a known property of 'div'. "`
我认为,这可能会发生,因为也许不是所有的对象都具有值是类别阵列。那么有没有办法确保*ng-if= "{{object?.categories[0]?.slug}} == single"
条件仅在确保类别数组非空后才被检查?我们也可以在同一个div上同时拥有条件和循环吗?
其* ngIf .. !!! –
角度没有'ng-if'指令。你应该使用'* ngIf'而不是 – yurzui
我在这里提到:https://stackoverflow.com/questions/34766128/ionic-if-else-statement-to-display-and-show-data – OshoParth