+1 vote
in Angular by
What are Angular 2 directives? Explain with examples.

1 Answer

0 votes
by

A directive is a custom HTML element that is used to extend the power of HTML. Angular 2 has the following directives that get called as part of the BrowserModule module.

ngIf −

The ngif element is used to add elements to the HTML code if it evaluates to true, else it will not add the elements to the HTML code.

Syntax

*ngIf = 'expression' 

If the expression evaluates to true then the corresponding gets added, else the elements are not added.

ngFor −

The ngFor element is used to elements based on the condition of the For loop.

Syntax

*ngFor = 'let variable of variablelist' 

The variable is a temporary variable to display the values in the variablelist.

Related questions

0 votes
asked Jan 6, 2020 in Angular by sharadyadav1986
0 votes
asked Feb 15, 2020 in Angular by matthenary
...