@@ -42,15 +42,16 @@ arrangement isolates the controller from the directive as well as from DOM. This
42
42
point since it makes the controllers view agnostic, which greatly improves the testing story of
43
43
the applications.
44
44
45
- <example>
45
+ <example module="scopeExample" >
46
46
<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
+ }]);
54
55
</file>
55
56
<file name="index.html">
56
57
<div ng-controller="MyController">
@@ -122,28 +123,28 @@ inheritance, and child scopes prototypically inherit from their parents.
122
123
This example illustrates scopes in application, and prototypical inheritance of properties. The example is followed by
123
124
a diagram depicting the scope boundaries.
124
125
125
- <example>
126
+ <example module="scopeExample" >
126
127
<file name="index.html">
127
128
<div class="show-scope-demo">
128
- <div ng-controller="GreetCtrl ">
129
+ <div ng-controller="GreetController ">
129
130
Hello {{name}}!
130
131
</div>
131
- <div ng-controller="ListCtrl ">
132
+ <div ng-controller="ListController ">
132
133
<ol>
133
134
<li ng-repeat="name in names">{{name}} from {{department}}</li>
134
135
</ol>
135
136
</div>
136
137
</div>
137
138
</file>
138
139
<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
+ }]);
147
148
</file>
148
149
<file name="style.css">
149
150
.show-scope-demo.ng-scope,
@@ -190,14 +191,15 @@ Scopes can propagate events in similar fashion to DOM events. The event can be {
190
191
ng.$rootScope.Scope#$broadcast broadcasted} to the scope children or {@link
191
192
ng.$rootScope.Scope#$emit emitted} to scope parents.
192
193
193
- <example>
194
+ <example module="eventExample" >
194
195
<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
+ }]);
201
203
</file>
202
204
<file name="index.html">
203
205
<div ng-controller="EventController">
0 commit comments