Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Update controller.ngdoc #8011

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions docs/content/guide/controller.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,22 @@ The properties contain the **view model** (the model that will be presented by t
`$scope` properties will be available to the template at the point in the DOM where the Controller
is registered.

The following example shows a very simple constructor function for a Controller, `GreetingController`,
The following example demonstrates setting up
`GreetingController`,
which attaches a `greeting` property containing the string `'Hola!'` to the `$scope`:

We attach the controller as a module on the application using the `.controller` method of your
{@link module Angular Module}. This keeps it out of the global scope.

```js
function GreetingController($scope) {
var myApp = angular.module('myApp',[]);

myApp.controller('GreetingController', ['$scope', function($scope) {
$scope.greeting = 'Hola!';
}
}]);
```


Once the Controller has been attached to the DOM, the `greeting` property can be data-bound to the
template:

Expand All @@ -55,17 +62,7 @@ template:
</div>
```

**NOTE**: Although Angular allows you to create Controller functions in the global scope, this is
not recommended. In a real application you should use the `.controller` method of your
{@link module Angular Module} for your application as follows:

```js
var myApp = angular.module('myApp',[]);

myApp.controller('GreetingController', ['$scope', function($scope) {
$scope.greeting = 'Hola!';
}]);
```

We have used an **inline injection annotation** to explicitly specify the dependency
of the Controller on the `$scope` service provided by Angular. See the guide on
Expand Down Expand Up @@ -333,6 +330,3 @@ describe('state', function() {
});
});
```