簡體   English   中英

無法綁定到“*ngFor”,因為它不是“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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM