问题
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