简体   繁体   English

ng-template中的材料菜单不起作用

[英]material menu inside ng-template doesn't work

<span *ngIf="!slot.teiletyp.finished; else finishedPart" mat-line>
                Charge: {{ queue.box.batch_number }}
                </span>
                <ng-template #finishedPart>
                        <span mat-line >Fertigteilbox</span>
                        <mat-menu #menu="matMenu">
                        <button mat-menu-item (click)="boxClicked(queue.box)">boxdetail</button>
                        <button mat-menu-item (click)="openBoxes(queue.box.id)">offenebox</button>
                        </mat-menu>
                </ng-template>

here i am trying to open a menu in the else part but i am unable to doso. 在这里,我试图在其他部分打开菜单,但我无法这样做。 can someone help me with this. 有人可以帮我弄这个吗。

Thank you 谢谢

The menu is not opened by default. 默认情况下不打开菜单。 You have to add a menu trigger in order to open the menu. 您必须添加菜单触发器才能打开菜单。 In your case, a better solution would be to just use mat-button in your template. 在您的情况下,更好的解决方案是仅在模板中使用mat-button

<span *ngIf="!slot.teiletyp.finished; else finishedPart" mat-line>
  Charge: {{ queue.box.batch_number }}
</span>
<ng-template #finishedPart>
    <span mat-line>Fertigteilbox</span>
    <div>
        <button mat-button [ngStyle]="{'width':'100%'}" (click)="boxClicked(queue.box)">boxdetail</button>
        <mat-divider></mat-divider>
        <button mat-button [ngStyle]="{'width':'100%'}" (click)="openBoxes(queue.box.id)">offenebox</button>
    </div>
</ng-template>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM