mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +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
|
||||
|
||||
Controllers are classes which are responsible for application behavior. The recommended way of
|
||||
declaring controllers is:
|
||||
declaring controllers is using the array notation:
|
||||
|
||||
<pre>
|
||||
var MyController = function($scope, dep1, dep2) {
|
||||
someModule.controller('MyController', ['$scope', 'dep1', 'dep2', function($scope, dep1, dep2) {
|
||||
...
|
||||
$scope.aMethod = function() {
|
||||
...
|
||||
}
|
||||
}
|
||||
MyController.$inject = ['$scope', 'dep1', 'dep2'];
|
||||
...
|
||||
}]);
|
||||
</pre>
|
||||
|
||||
This avoids the creation of global functions for controllers and also protects against minification.
|
||||
|
||||
|
||||
### Factory methods
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue