Explain ngIf directive with an example.

devquora
devquora

Posted On: Feb 22, 2018

 

The ngIf is a built-in template directive that is used to add or remove some parts of DOM. This addition or removal depends on the expression being true or false.

If the expression is evaluated to false, then the ngIf directive removes the HTML element. If the expression is evaluated to be true, then the element gets added to the DOM.

Syntax- *ngIf="<condition>"

Example-


	   	<ul *ngFor="let person of people"

		*ngIf="person.age < 30">

		<li>{{person.name}}</li></ul>
	

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Angular 4 Interview Questions

    Explain component decorators in Angular4.

    A decorator is the core concept when developing an angular framework with version 2 and above. It may become a core lang..

    Angular 4 Interview Questions

    Write the CLI command to generate a component in Angular4.

    Components are just simple classes which are declared as components with the help of component decorators. It becomes e..

    Angular 4 Interview Questions

    Explain the component directory structure of angular4.

    Here are the elements which are present in the component directory structure anf modules:-module.ts- in this, the angu..