mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-14 17:53:11 +00:00
docs(di): promote registering controllers on modules
This commit is contained in:
parent
1122b3c14d
commit
caa12dbc57
1 changed files with 6 additions and 4 deletions
|
|
@ -196,18 +196,20 @@ DI is pervasive throughout Angular. It is typically used in controllers and fact
|
||||||
### DI in controllers
|
### DI in controllers
|
||||||
|
|
||||||
Controllers are classes which are responsible for application behavior. The recommended way of
|
Controllers are classes which are responsible for application behavior. The recommended way of
|
||||||
declaring controllers is:
|
declaring controllers is using the array notation:
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
var MyController = function($scope, dep1, dep2) {
|
someModule.controller('MyController', ['$scope', 'dep1', 'dep2', function($scope, dep1, dep2) {
|
||||||
...
|
...
|
||||||
$scope.aMethod = function() {
|
$scope.aMethod = function() {
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
}
|
...
|
||||||
MyController.$inject = ['$scope', 'dep1', 'dep2'];
|
}]);
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
This avoids the creation of global functions for controllers and also protects against minification.
|
||||||
|
|
||||||
|
|
||||||
### Factory methods
|
### Factory methods
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue