Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6f465a2

Browse files
committed
docs(guide/scope): update examples to use modules
1 parent 3ecac62 commit 6f465a2

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

docs/content/guide/scope.ngdoc

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,16 @@ arrangement isolates the controller from the directive as well as from DOM. This
4242
point since it makes the controllers view agnostic, which greatly improves the testing story of
4343
the applications.
4444

45-
<example>
45+
<example module="scopeExample">
4646
<file name="script.js">
47-
function MyController($scope) {
48-
$scope.username = 'World';
49-
50-
$scope.sayHello = function() {
51-
$scope.greeting = 'Hello ' + $scope.username + '!';
52-
};
53-
}
47+
angular.module('scopeExample', [])
48+
.controller('MyController', ['$scope', function($scope) {
49+
$scope.username = 'World';
50+
51+
$scope.sayHello = function() {
52+
$scope.greeting = 'Hello ' + $scope.username + '!';
53+
};
54+
}]);
5455
</file>
5556
<file name="index.html">
5657
<div ng-controller="MyController">
@@ -122,28 +123,28 @@ inheritance, and child scopes prototypically inherit from their parents.
122123
This example illustrates scopes in application, and prototypical inheritance of properties. The example is followed by
123124
a diagram depicting the scope boundaries.
124125

125-
<example>
126+
<example module="scopeExample">
126127
<file name="index.html">
127128
<div class="show-scope-demo">
128-
<div ng-controller="GreetCtrl">
129+
<div ng-controller="GreetController">
129130
Hello {{name}}!
130131
</div>
131-
<div ng-controller="ListCtrl">
132+
<div ng-controller="ListController">
132133
<ol>
133134
<li ng-repeat="name in names">{{name}} from {{department}}</li>
134135
</ol>
135136
</div>
136137
</div>
137138
</file>
138139
<file name="script.js">
139-
function GreetCtrl($scope, $rootScope) {
140-
$scope.name = 'World';
141-
$rootScope.department = 'Angular';
142-
}
143-
144-
function ListCtrl($scope) {
145-
$scope.names = ['Igor', 'Misko', 'Vojta'];
146-
}
140+
angular.module('scopeExample', [])
141+
.controller('GreetController', ['$scope', '$rootScope', function($scope, $rootScope) {
142+
$scope.name = 'World';
143+
$rootScope.department = 'Angular';
144+
}])
145+
.controller('ListController', ['$scope', function($scope) {
146+
$scope.names = ['Igor', 'Misko', 'Vojta'];
147+
}]);
147148
</file>
148149
<file name="style.css">
149150
.show-scope-demo.ng-scope,
@@ -190,14 +191,15 @@ Scopes can propagate events in similar fashion to DOM events. The event can be {
190191
ng.$rootScope.Scope#$broadcast broadcasted} to the scope children or {@link
191192
ng.$rootScope.Scope#$emit emitted} to scope parents.
192193

193-
<example>
194+
<example module="eventExample">
194195
<file name="script.js">
195-
function EventController($scope) {
196-
$scope.count = 0;
197-
$scope.$on('MyEvent', function() {
198-
$scope.count++;
199-
});
200-
}
196+
angular.module('eventExample', [])
197+
.controller('EventController', ['$scope', function($scope) {
198+
$scope.count = 0;
199+
$scope.$on('MyEvent', function() {
200+
$scope.count++;
201+
});
202+
}]);
201203
</file>
202204
<file name="index.html">
203205
<div ng-controller="EventController">

0 commit comments

Comments
 (0)