diff options
| author | Misko Hevery | 2011-12-14 02:55:31 +0100 |
|---|---|---|
| committer | Misko Hevery | 2012-01-25 11:53:59 -0800 |
| commit | 4804c83b7db5770d5d02eea9eea4cc012b4aa524 (patch) | |
| tree | be5ae1743179704cc1638f186cddba8d6e3fa37d /docs/content/guide/dev_guide.mvc.understanding_controller.ngdoc | |
| parent | e2b1d9e994e50bcd01d237302a3357bc7ebb6fa5 (diff) | |
| download | angular.js-4804c83b7db5770d5d02eea9eea4cc012b4aa524.tar.bz2 | |
docs(compiler): update the compiler docs
Diffstat (limited to 'docs/content/guide/dev_guide.mvc.understanding_controller.ngdoc')
| -rw-r--r-- | docs/content/guide/dev_guide.mvc.understanding_controller.ngdoc | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/docs/content/guide/dev_guide.mvc.understanding_controller.ngdoc b/docs/content/guide/dev_guide.mvc.understanding_controller.ngdoc index 5f571680..c308e399 100644 --- a/docs/content/guide/dev_guide.mvc.understanding_controller.ngdoc +++ b/docs/content/guide/dev_guide.mvc.understanding_controller.ngdoc @@ -24,8 +24,8 @@ constructor). Constructors are always applied to an existing scope object. You set up the initial state of a scope by creating model properties. For example: -function GreetingCtrl() { - this.greeting = 'Hola!'; +function GreetingCtrl($scope) { + $scope.greeting = 'Hola!'; } The `GreetingCtrl` controller creates a `greeting` model which can be referred to in a template. @@ -43,7 +43,7 @@ As discussed in the {@link dev_guide.mvc.understanding_model Model} section of t objects (or primitives) assigned to the scope become model properties. Any functions assigned to the scope, along with any prototype methods of the controller type, become functions available in the template/view, and can be invoked via angular expressions and `ng:` event handlers (e.g. {@link -api/angular.directive.ng:click ng:click}). These controller methods are always evaluated within the +api/angular.module.ng.$compileProvider.directive.ng:click ng:click}). These controller methods are always evaluated within the context of the angular scope object that the controller function was applied to (which means that the `this` keyword of any controller method is always bound to the scope that the controller augments). This is how the second task of adding behavior to the scope is accomplished. @@ -78,7 +78,7 @@ instances). # Associating Controllers with Angular Scope Objects You can associate controllers with scope objects explicitly via the {@link api/angular.module.ng.$rootScope.Scope#$new -scope.$new} api or implicitly via the {@link api/angular.directive.ng:controller ng:controller +scope.$new} api or implicitly via the {@link api/angular.module.ng.$compileProvider.directive.ng:controller ng:controller directive} or {@link api/angular.module.ng.$route $route service}. @@ -105,9 +105,9 @@ string "very". Depending on which button is clicked, the `spice` model is set to <p>The food is {{spice}} spicy!</p> </body> -function SpicyCtrl() { - this.spice = 'very'; - this.chiliSpicy = function() { +function SpicyCtrl($scope) { + $scope.spice = 'very'; + $scope.chiliSpicy = function() { this.spice = 'chili'; } } @@ -144,9 +144,9 @@ previous example. <p>The food is {{spice}} spicy!</p> </body> -function SpicyCtrl() { - this.spice = 'very'; - this.spicy = function(spice) { +function SpicyCtrl($scope) { + $scope.spice = 'very'; + $scope.spicy = function(spice) { this.spice = spice; } } @@ -171,18 +171,18 @@ have a look at an example: <p ng:controller="BabyCtrl">Good {{timeOfDay}}, {{name}}!</p> </body> -function MainCtrl() { - this.timeOfDay = 'morning'; - this.name = 'Nikki'; +function MainCtrl($scope) { + $scope.timeOfDay = 'morning'; + $scope.name = 'Nikki'; } -function ChildCtrl() { - this.name = 'Mattie'; +function ChildCtrl($scope) { + $scope.name = 'Mattie'; } -function BabyCtrl() { - this.timeOfDay = 'evening'; - this.name = 'Gingerbreak Baby'; +function BabyCtrl($scope) { + $scope.timeOfDay = 'evening'; + $scope.name = 'Gingerbreak Baby'; } </pre> |
