我試圖從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