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

  

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
angular add custom directive conditionally angular condition directive conditionally add directive angular directive based on condition angular directive conditional if condition in angualr directive apply directive conditionally angular angular directive on condition angular conditional add directive directives angular if statement angular add directive conditionally Apply a directive conditionally angularjs conditionaly put a custom directive in angular conditionaly put a directive in angular conditional directive angular apply directive if angular directive if conditionally add directive angular apply directive conditionally angularjs conditionally add a directive Conditional use of #include Directive conditionaly add a directive angular add directive conditionally angular using conditional rendering using directives in angular ng custom conditional directive ng conditional directive angular apply directive conditionally how to apply directive conditionally angular directive if angular *ngif case angular conditionally add attribute directive angular add directive on condition add or remove button type conditionally angular 8 angular if ng s or ng b ngif ng template ng template ngif condition rendering in angular can i write for ngIf anchor tag in angular10 span ngif angular 6 use ngif to chcek binding value ngif not condition or condition angular conditionnally add/remove directive attribe conditional directive angular angular conditionally bind directive conditional directive angular 6 angular conditional directive reference self in ngif html angular directive ngif and ngif angular conditional directive angular 7 angular 7 add directive conditionally angular 10 [cdkDrag] attribute ngIF ngif angular with one element conditionbase directive on element angular include directive in html conditionally how to check three error message based on user input in angular using ngif and ngtemplate add ngif in ng-template Angular + conditional directive on template assign directive conditionally angular angular conditional directives
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source