include ../_util-fns :marked One of the defining features of a single page application is its manipulation of the DOM tree. Instead of serving a whole new page every time a user navigates, whole sections of the DOM appear and disappear according to the application state. In this chapter we'll to look at how Angular manipulates the DOM and how we can do it ourselves in our own directives. In this chapter we will - [learn what structural directives are](#definition) - [study *ngIf*](#ng-if) - [discover the <template> element](#template) - [understand the asterisk (\*) in **ngFor*](#asterisk) - [write our own structural directive](#unless) [Live example](/resources/live-examples/structural-directives/ts/plnkr.html) .l-main-section :marked ## What are structural directives? There are three kinds of Angular directives: 1. Components 1. Attribute directives 1. Structural directives The *Component* is really a directive with a template. It's the most common of the three directives and we write lots of them as we build our application. The [*Attribute* directive](attribute-directives.html) changes the appearance or behavior of an element. The built-in [NgStyle](template-syntax.html#ngStyle) directive, for example, can change several element styles at the same time. We can use it to render text bold, italic, and lime green by binding to a component property that requests such a sickening result. A *Structural* directive changes the DOM layout by adding and removing DOM elements. We've seen three of the built-in structural directives in other chapters: [ngIf](template-syntax.html#ngIf), [ngSwitch](template-syntax.html#ngSwitch) and [ngFor](template-syntax.html#ngFor). +makeExample('structural-directives/ts/app/structural-directives.component.html', 'structural-directives')(format=".") .l-main-section :marked ## NgIf Case Study Let’s focus on `ngIf`. It's a great example of a structural directive: it takes a boolean and makes an entire chunk of DOM appear or disappear. +makeExample('structural-directives/ts/app/structural-directives.component.html', 'ngIf')(format=".") :marked The `ngIf` directive does not hide the element. Using browser developer tools we can see that, when the condition is true, the top paragraph is in the DOM and the bottom disused paragraph is completely absent from the DOM! In its place are empty `