12 Using the built-in directives

 

This chapter covers

  • Using the ngIf and ngSwitch directives to selectively include elements
  • Using the ngFor directive to generate content for each element in a sequence
  • Using micro-templates to repeat content
  • Understanding the restrictions Angular places on data binding expressions

In this chapter, I describe the built-in directives that are responsible for some of the most commonly required functionality for creating web applications: selectively including content, choosing between different fragments of content, and repeating content. I also describe some limitations that Angular puts on the expressions that are used for one-way data bindings and the directives that provide them. Table 12.1 puts the built-in template directives in context.

12.1 Preparing the example project

12.2 Using the built-in directives

12.2.1 Using the ngIf directive

12.2.2 Using the ngSwitch directive

12.2.3 Using the ngFor directive

12.2.4 Using the ngTemplateOutlet directive

12.2.5 Using directives without an HTML element

12.3 Understanding one-way data binding restrictions

12.3.1 Using idempotent expressions

12.3.2 Understanding the expression context

12.4 Summary