Implementing the Scope Model

After the controller has been defined, you can implement the scope, which involves linking HTML elements to scope variables, initializing the variables in the scope, and providing functionality to handle changes to the scope values.

Lines 9 and 10 in Listing 2.1 are <input> elements that are assigned to the first and last values in the scope. These elements provide a method to update the scope from the browser. If the user types in the input, the scope is also updated:

09       <input type="text" ng-model="first">10       <input type="text" ng-model="last">

Lines 3–5 in Listing 2.2 show the initial values of the scope being defined:

03   $scope.first = 'Some'; ...

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.