Criado por James Drummond
quase 9 anos atrás
|
||
The syntax InvoiceController as invoice tells Angular to instantiate the controller and save it in the variable invoice in the current scope.What this means is that you can treat the controller as an object:myApp.controller()You need to be very careful about context: this is what you need to do to use $scope.$watch with this syntax: note binding of thisapp.controller('MainCtrl', function ($scope) { this.title = 'Some title'; // boom $scope.$watch(angular.bind(this, function () { return this.title; // `this` IS the `this` above!! }), function (newVal, oldVal) { // now we will pickup changes to newVal and oldVal }); });
Quer criar suas próprias Notas gratuitas com a GoConqr? Saiba mais.