【问题标题】:I want to use href to decide which modal needs to be toggled open我想使用 href 来决定需要打开哪个模式
【发布时间】:2021-06-12 18:43:45
【问题描述】:

我有两个模态,id="detailsModal"id="messageModal"。根据我从后端收到的响应,我设置了 errorMessage 的值,在没有错误的情况下为 null。根据这个,我想决定href。我已经使用以下代码来执行此操作,但它不起作用。

href="{{errorMessage === null ? '#detailsModal' : '#messageModal'}}"

【问题讨论】:

    标签: angular href


    【解决方案1】:

    您可以使用 ng-template 和 NgIf 来完成此操作。 https://angular.io/api/common/NgIf

    你可以用你的错误来做到这一点:

    <div *ngIf="errorMessage === null; then thenBlock; else elseBlock">this is ignored</div>
    <ng-template #thenBlock>Then text to show</ng-template>
    <ng-template #elseBlock>Else text to show</ng-template>
    

    【讨论】:

    • 您好,感谢您的回答。但是,我使用相同的模式来显示多个错误,因此我无法将其用于我的目的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-03
    • 2018-06-03
    • 1970-01-01
    • 1970-01-01
    • 2021-07-31
    • 2020-07-30
    相关资源
    最近更新 更多