Answers for "use ngif to chcek binding value"

1

ngif

<div *ngIf="condition; else elseBlock">
         
<button class="xx" *ngIf="flag" (click)="doFunct()">Next</button>
   
--While (t/f boolean variable called "flag") is true
  This button will be visible + click button executes function
  Once this "flag" becomes false this button disapears
Posted by: Guest on June-20-2020
-1

angular conditional directives

//if 
<div *ngIf='[condition]'> </div>   
  //if [condition]==true the div will be shown

//for 
<div *ngFor='let [data] of [dataArray]; let i=index;'>
  <h2> {{i}} {{data.title}} </h2>
  <img src='{{data.image}}' />
  </div>   
  //the data contained in an array will be displayed element by element
  //similar to the function .map() in React

// ngStyle (conditional Style)
<div *ngFor='let [data] of [dataArray]; let i=index;'>
  <h2 [style.background]="i>1? 'green': 'red'"> {{i}} {{data.title}} </h2>

  </div> 

//if the index of the element is 1 or 0, the background will be red, if it is over 1 the background will be green
Posted by: Guest on October-12-2020

Browse Popular Code Answers by Language