Fan Cheung
Fan Cheung

Reputation: 11345

Angular multiple ngIf multiple condition assign as value?

how do you assign a as value when there is multiple condition using *ngIf

e.g can i pass either orange or apple as "as value"

<div *ngIf="orange && apple as apple">
...
</div> 

Upvotes: 0

Views: 676

Answers (1)

Adrian Brand
Adrian Brand

Reputation: 21638

<div *ngIf="orange && apple">
  ...
</div>

Will show the div if both apple and orange are truthy.

<div *ngIf="(orange && apple) as appleAndOrange">
  ...
</div>

Will show the div if both apple and orange are truthy and define a view variable called appleAndOrange available to the children of the div but it will always contain the value of apple as it is second in and and statement.

Upvotes: 1

Related Questions