What is Directive in Angular?

The directive is a function that executes whenever the Angular compiler finds it in the DOM.
There are two types of directives in Angular.

  • Attribute Directive-Change the properties of the HTML element when it gets applied
 <div upperCase>
 <p>some text</p>

When a directive applied, it will change the text to uppercase.$ads={1}

  • Structural directives- Add or remove HTML elements from the DOM
    <div *ngIf="var.length>0">
     <p>Display only if var exists</p>
Next Post Previous Post
No Comment
Add Comment
comment url