【问题标题】:How to add routerLink on ternary operator?如何在三元运算符上添加routerLink?
【发布时间】:2021-02-22 18:09:47
【问题描述】:

在我的角度 HTML 代码中有如下所示的三元条件

<my-tag [top-position]="find.distance ? find.distance.code : find.volume.code" [rClass]="r.rClass"></my-tag>

我正在尝试使上述内容可点击,以便当用户点击时,他们会被重定向到不同的路线。我很难将 routerLink 集成到上述代码中

【问题讨论】:

  • [routerLink]="condition ? ['/my-path'] : null"

标签: angular onclick href router


【解决方案1】:

就我而言,我必须按学校类型进行路由!

在 .ts 文件中

edType: string;
ngOnInit(){ this.edType == 'M' }

在 HTML 中

<ion-item button detail [routerLink]="[edType == 'M' ? 'middle-school' : 'high-school']">
   <ion-icon name="log-in-outline" slot="start"></ion-icon>
    <ion-label> Switch School </ion-label>
</ion-item>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-05
    • 2017-05-23
    • 2022-01-04
    • 2021-09-18
    • 2015-05-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多