Test
data ` `
Test
data
` `
Test
data
` `

Template logic based out of two different text

65 Views Asked by At

Need to show two different texts based out of a boolean Value.

I tried this

    <div name="health-plans" *ngIf="!flagon">
      Test<br />data
    </div>`

`        <div name="health-plans" *ngIf="flagon">
          Test data <br /> & value
        </div>

But I need to simpify this with one div based out on condition.

1

There are 1 best solutions below

4
nate-kumar On

Angular 17+

<div name="health-plans">
  @if (!flagon) {
    Test<br />data
  }
  @else {
    Test data <br /> & value
  }
</div>

Angular <17

<div name="health-plans">
  <ng-container *ngIf="!flagon; else FlagonTemplate">
    Test<br />data
  </ng-container>

  <ng-template #FlagonTemplate>
    Test data <br /> & value
  </ng-template>
</div>