首页 > 解决方案 > 带有条件的模板上的属性绑定

问题描述

我有一个代表菜单的通用组件。对于某些按钮,我想重定向到其他状态,对于菜单上的某些按钮,我想在同一页面内执行操作。

 <ng-container *ngFor="let item of section.items">
      <button mat-menu-item
                    [disabled]="item.disabled"
                    [routerLink]="item.link? item.link: undefined"
                    [queryParams]="{institution: institutionCode}"
                    (click)="!item.link ? onItemAction(item.action) : undefined">
                          {{item.label}}
            </button>
</ng-container>

问题是,当我想执行一项操作并保持在同一页面上时,queryParams 被删除并设置为仅“机构”。有没有更好的方法在不复制按钮的情况下将 [routerLink] 和 [queryParams] 属性包含在条件中,一个带有这些属性,一个没有,每个都带有 *ngIf?我只是希望当我没有归属的链接时不会出现并更改 mu url。

标签: javascriptangulartypescript

解决方案


推荐阅读