![](/img/trans.png)
[英]Angular: ternary operator in ngFor throw error Can't bind to 'ngFor' since it isn't a known property of 'div'
[英]Can't bind to '*ngFor' since it isn't a known property of 'div'
我試圖在*ngFor
中綁定filter
的值。 但它沒有正常工作。 如何將數據綁定到ngFor
?
源代碼如下,
在.ts
文件中,
menuIcons:any[];
public pageName:any = "projects";
this.menuIcons=[{
'id':'0',
'name':'',
'cat':'default'
},
{
'id':'1',
'name':'apps',
'cat':'projects'
}];
我在.html
文件中嘗試了以下代碼,
第一次嘗試 --> filter:'{{pageName}}'
<div class="Container" style="position:relative" *ngFor="let icon of menuIcons | filter:'{{pageName}}' ">
<button mat-button class="user-button" >
<mat-icon class="s-28">{{icon.name}}</mat-icon>
</button>
</div>
第二次嘗試 --> filter:'${pageName}'
<div class="Container" style="position:relative" *ngFor="let icon of menuIcons | filter:'${PageName}' ">
<button mat-button class="user-button" >
<mat-icon class="s-28">{{icon.name}}</mat-icon>
</button>
</div>
vs 代碼顯示錯誤Can't bind to '*ngFor' since it isn't a known property of 'div'
我怎樣才能解決這個問題?
你有沒有嘗試過這樣的事情:
<div class="Container" style="position:relative"
*ngFor="let icon of menuIcons | filter:PageName">
<button mat-button class="user-button" >
<mat-icon class="s-28">{{icon.name}}</mat-icon>
</button>
</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.