Write the syntax for ngIf Directive. Why is it used?

DWQA QuestionsCategory: QuestionsWrite the syntax for ngIf Directive. Why is it used?
Editor Staff asked 1 month ago

Write the syntax for ngIf Directive. Why is it used?

1 Answers
Editor Staff answered 1 month ago

The syntax of the ngIf Directive is given below

<p *ngIf="condition">    
    condition is true and ngIf is true.    
</p>    
<p *ngIf="!condition">    
    condition is false and ngIf is false.    
</p>

The usage of ngIf is described below –
It is a structural directive present in Angular Version 8 whose usage revolves around adding or removing HTML elements based on the expression statement. The functioning of this nglf directive is observed as follows: When the expression is true, the element is added and when the expression is false, the element is removed using this directive.