What are Angular directives? Provide examples of built-in directives.

Answer

Angular directives are instructions that modify the behavior or appearance of HTML elements within an Angular application. They are used to extend HTML with additional functionality and provide a way to interact with the DOM.

Examples of built-in directives in Angular:

  1. ngIf: Conditionally adds or removes elements from the DOM based on a given expression

         <div *ngIf="showElement">This element is conditionally displayed.</div>

      

  1. ngFor: Iterates over a collection and creates a template for each item.

<ul>
<li *ngFor="let item of items">{{ item }}</li>
</ul>

   

  1. ngStyle: Binds styles to an element based on a given expression.

<div [ngStyle]="{ 'color': textColor, 'font-size': fontSize + 'px' }">Styled Text</div>

 

All angular Questions

Ask your interview questions on angular

Write Your comment or Questions if you want the answers on angular from angular Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---