Improved semantics of the directives syntax

In Chapter 1, Get Going with Angular, we mentioned the opportunity for improved tooling in Angular. A big issue in AngularJS is the different ways in which we can use directives. This requires an understanding of the attribute values, which can be literals, expressions, callbacks, or a microsyntax. Starting with Angular 2, this problem is eliminated by introducing a few simple conventions that are built into the framework:

  • propertyName="value"
  • [propertyName]="expression"
  • (eventName)="handler()"

In the first line, the propertyName attribute accepts a string literal as a value. Angular will not process the attribute's value any further; it will use it the way it is set in the template.

The second syntax, ...

Get Getting Started with Angular - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.