Two-way data binding and templates

Two-way data binding is one of the most interesting parts of AngularJS. It is responsible for synchronizing changes made to Model, and it manipulates DOM instantly. Without their help, it would need to write many, many lines of code to monitor changes to Model and return them to update DOM.

Let's see the following code, which illustrates the data binding:

<div ng-controller="UserController">
  <h1>{{ user.name }} - {{ user.age }}</h1>
  <p ng-bind="user.name"></p>
  <p ng-bind="user.age"></p>
  <br>
  <input type="text" ng-model="user.name">
  <input type="text" ng-model="user.age">
</div>

Just below the <h1> tag, where we used the expression with double brackets, we can see two paragraphs with the ng-bind directive; it does ...

Get Learning Single-page Web Application Development 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.