How to render list of items inside Mat-Menu Angular/material2

a 夏天 提交于 2019-12-11 03:14:25

问题


Back in materialc1 I was able to render a list of buttons inside my material menu as below:

  <md-menu>
  <md-button ng-click="vm.openMenu($mdMenu, $event)">     
     <md-icon md-svg-icon="extraIcons:toolbox" aria-label="Toolbox"></md-icon>
  </md-button>
  <md-menu-content>
    <md-menu-item ng-repeat="hi in vm.ListofPizza">          
     <md-button ng-click="vm.orderPizza(hi.id)">                        
         {{hi.name}}          
    </md-button>            
  </md-menu-item>
 </md-menu-content>

I am trying to do the same in material2/angular2 as shown below:

<button mat-fab color="primary" [matMenuTriggerFor]="menu">
<mat-icon svgIcon="extraIcons:toolbox">
</mat-icon>   
</button>
<mat-menu #menu="matMenu">
<mat-menu-item *ngFor="let hi ofListofPizza">                 
<button mat-button> {{hi.name}}</button>
</mat-menu-item>

However this gives me below mentioned error:

Can't have multiple template bindings on one element. Use only one attribute named 'template' or prefixed with * ("

menu="matMenu">

What am i doing wrong?


回答1:


Thats how its supposed to be.

<mat-menu #menu="matMenu">
  <button mat-menu-item *ngFor="let item of ofListofPizza">
    {{ item.text }}
  </button>
</mat-menu>


来源:https://stackoverflow.com/questions/48300898/how-to-render-list-of-items-inside-mat-menu-angular-material2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!