代码之家  ›  专栏  ›  技术社区  ›  Kiara

根据条件角度显示多个模板

  •  0
  • Kiara  · 技术社区  · 11 月前

    我有一个按钮,我将根据条件显示工具提示,现在我有了一个显示工具提示的条件,现在我还有另一组需要显示不同消息的条件

    <div *ngIf="!assessmentDetailsObj" placement="top-right" [mtTooltip]="(!lob || lob === undefined) ? disabledLOBContent : ''">
              <button
                *ngIf="!assessmentDetailsObj"
                [disabled]="(!lob || lob === undefined)"
                class="btn btn-primary"
                aria-label="Accept"
                (click)="create()"
              >
                Create
              </button>
            </div>
            <ng-template #disabledLOBContent>Please Select LOB</ng-template>
    

    现在我想添加另一组条件

    [mtTooltip]="isTrueSet ? refVar : ''"
    <ng-template #refVar>Please select Endpoints</ng-template>
    

    我可以绑定吗 [mtTooltip] 对于一个函数和内部函数,我可以检查多个条件吗?基于此,我可以显示消息吗?

    1 回复  |  直到 11 月前
        1
  •  1
  •   Random    11 月前

    如果你的模板足够简单,你实际上可以把你的条件放在你的模板里,而不是制作多个模板,让你的条件变得复杂:

    <ng-template #disabledLOBContent>
      <ng-container *ngIf="myContition1">Please Select LOB</ng-container>
      <ng-container *ngIf="myContition2">An other message</ng-container>
      <ng-container *ngIf="myContition3">An other diffrent message</ng-container>
    </ng-template>