Skip to content

Commit 1adb1a5

Browse files
amirhhzjamessharp
authored andcommitted
docs(guide): change prototype methods to scope methods in DI examples
As explained in 'Understanding the Controller Component', Controllers written for new (post 1.0 RC) versions of Angular need to add methods to the scope directly, not the function's prototype. Correcting this example should remove any ambiguity, especially for beginners.
1 parent ab34819 commit 1adb1a5

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

docs/content/guide/di.ngdoc

+5-6
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,13 @@ Controllers are classes which are responsible for application behavior. The reco
196196
declaring controllers is:
197197

198198
<pre>
199-
var MyController = function(dep1, dep2) {
200-
...
201-
}
202-
MyController.$inject = ['dep1', 'dep2'];
203-
204-
MyController.prototype.aMethod = function() {
199+
var MyController = function($scope, dep1, dep2) {
205200
...
201+
$scope.aMethod = function() {
202+
...
203+
}
206204
}
205+
MyController.$inject = ['$scope', 'dep1', 'dep2'];
207206
</pre>
208207

209208

0 commit comments

Comments
 (0)