Learning Angular for .NET Developers
上QQ阅读APP看书,第一时间看更新

Structural directives

Structural directives deal with modifying elements in the DOM by adding new elements, removing existing elements, and replacing existing elements with new elements. The following markup shows two structural directives: *ngFor and *ngIf:

<div *ngFor="#todo of todos"></div> 
<todo-item *ngIf="selectedTodo"></todo-item>

*ngFor iterates through each item in the todos collection and adds a div tag for each item. And *ngIf renders <todo-item> only if selectedTodo is available.