Return to site

ANGULAR INTERVIEW QUESTION: What are the different kinds of Angular directives?

ยท ngInterview,fullstack

๐“๐ก๐ž๐ซ๐ž ๐š๐ซ๐ž ๐ญ๐ก๐ซ๐ž๐ž ๐ค๐ข๐ง๐๐ฌ ๐จ๐Ÿ ๐๐ข๐ซ๐ž๐œ๐ญ๐ข๐ฏ๐ž๐ฌ:

๐Ÿ‘‰๐€๐ญ๐ญ๐ซ๐ข๐›๐ฎ๐ญ๐ž ๐๐ข๐ซ๐ž๐œ๐ญ๐ข๐ฏ๐ž๐ฌ

๐Ÿ‘‰๐‚๐จ๐ฆ๐ฉ๐จ๐ง๐ž๐ง๐ญ๐ฌ

๐Ÿ‘‰๐’๐ญ๐ซ๐ฎ๐œ๐ญ๐ฎ๐ซ๐š๐ฅ ๐๐ข๐ซ๐ž๐œ๐ญ๐ข๐ฏ๐ž๐ฌ

๐Ÿ) ๐“๐ก๐ž ๐š๐ญ๐ญ๐ซ๐ข๐›๐ฎ๐ญ๐ž ๐๐ข๐ซ๐ž๐œ๐ญ๐ข๐ฏ๐ž๐ฌ

They allow to modify the appearance and the behavior of a DOM element.

For example, ngStyle and ngClass.

You can make your own attribute directive.

Custom code:

Then you apply your custom directive on any DOM element or Angular component belonging to the same module:

๐Ÿ) ๐“๐ก๐ž ๐œ๐จ๐ฆ๐ฉ๐จ๐ง๐ž๐ง๐ญ๐ฌ

The components are directives that have a binded template, style sheet and a selector property WITHOUT brackets.

๐Ÿ‘) ๐“๐ก๐ž ๐ฌ๐ญ๐ซ๐ฎ๐œ๐ญ๐ฎ๐ซ๐š๐ฅ ๐๐ข๐ซ๐ž๐œ๐ญ๐ข๐ฏ๐ž๐ฌ

Thes directives modify the DOM by adding orremoving elements or elements children.

The ngIf and ngFor are examples of structural directives:

NB: the Angular structural directives have a star at the beginning of their selector.