Home > Net >  How to add <a> tag in Angular based on condition
How to add <a> tag in Angular based on condition

Time:06-07

How to add an <a> tag in Angular based on condition like

{{(mockupSheet==0) ? "No" : <a href="SomeLinke">mockupSheetActualValue</a>}}

CodePudding user response:

I think you're looking for *ngIF:

<div *ngIf="mockupSheet!==0; else other">
    <a href="SomeLinke">mockupSheetActualValue</a>
</div>
<ng-template #other>
   No
</ng-template>

CodePudding user response:

Use an *ngIf to display a template when the value returns truthy. You can use an else statement within the *ngIf attribute to display an alternative template if the if statement returns falsy value.

<a href="SomeLinke" *ngIf="mockupSheet !== 0; else no">mockupSheetActualValue</a>

<ng-template #no>
  <span>No</span>
</ng-template>

CodePudding user response:

Use *ngIf to show/hide depending on the given condition:

<div *ngIf="mockupSheet != 0; else noValue">
    <a href="SomeLinke">mockupSheetActualValue</a>
</div>

<ng-template #noValue>
    <a href="SomeLinke">No value</a>
</ng-template>
  • Related