The Relationship Between Scopes and Templates
Templates provide the view for an AngularJS application. HTML elements are defined as controllers, using the ng-controller
attribute. Inside a controller HTML element and its children, the scope for that controller is available for expressions and other AngularJS functionality.
Values in a scope can be directly linked to the values of <input>
, <select>
, and <textarea>
elements in the template, using the ng-model
directive. This directive links the value of an element to a property name in the scope. When the user changes the value of the input element, the scope is automatically updated. For example, the following links the value of a number of an <input>
element to the scope named valueA
:
Get Learning AngularJS 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.