"controller as" syntax for AngularJS 1.2+

Updated . Posted . Visible to the public.

In the Controller:

// Instead of doing this:
app.controller('TodoCtrl', function ($scope) {
  $scope.input = 'ex. buy milk';
});

// Do this:
app.controller('TodoCtrl', function () {
  this.input = 'ex. buy milk';
});

In the HTML:

<!-- Instead of this: -->
<div ng-controller="TodoCtrl">
  <input type="text" ng-model="input" />
</div>

<!-- Do this: --> 
<div ng-controller="TodoCtrl as todo">
  <input type="text" ng-model="todo.input" />
</div>
Last edit
Besprechungs-PC
License
Source code in this card is licensed under the MIT License.
Posted to makandra dev (2014-12-06 10:45)