@@ -16,9 +16,9 @@ The key directive in understanding two-way data-binding is {@link ng.directive:n
16
16
The `ngModel` directive provides the two-way data-binding by synchronizing the model to the view, as well as view to the model.
17
17
In addition it provides an {@link ngModel.NgModelController API} for other directives to augment its behavior.
18
18
19
- <example>
19
+ <example module="formExample" >
20
20
<file name="index.html">
21
- <div ng-controller="Controller ">
21
+ <div ng-controller="ExampleController ">
22
22
<form novalidate class="simple-form">
23
23
Name: <input type="text" ng-model="user.name" /><br />
24
24
E-mail: <input type="email" ng-model="user.email" /><br />
@@ -32,19 +32,20 @@ In addition it provides an {@link ngModel.NgModelController API} for other direc
32
32
</div>
33
33
34
34
<script>
35
- function Controller($scope) {
36
- $scope.master = {};
35
+ angular.module('formExample', [])
36
+ .controller('ExampleController', ['$scope', function($scope) {
37
+ $scope.master = {};
37
38
38
- $scope.update = function(user) {
39
- $scope.master = angular.copy(user);
40
- };
39
+ $scope.update = function(user) {
40
+ $scope.master = angular.copy(user);
41
+ };
41
42
42
- $scope.reset = function() {
43
- $scope.user = angular.copy($scope.master);
44
- };
43
+ $scope.reset = function() {
44
+ $scope.user = angular.copy($scope.master);
45
+ };
45
46
46
- $scope.reset();
47
- }
47
+ $scope.reset();
48
+ }]);
48
49
</script>
49
50
</file>
50
51
</example>
@@ -69,9 +70,9 @@ The following example uses the CSS to display validity of each form control.
69
70
In the example both `user.name` and `user.email` are required, but are rendered with red background only when they are dirty.
70
71
This ensures that the user is not distracted with an error until after interacting with the control, and failing to satisfy its validity.
71
72
72
- <example>
73
+ <example module="formExample" >
73
74
<file name="index.html">
74
- <div ng-controller="Controller ">
75
+ <div ng-controller="ExampleController ">
75
76
<form novalidate class="css-form">
76
77
Name:
77
78
<input type="text" ng-model="user.name" required /><br />
@@ -94,19 +95,20 @@ This ensures that the user is not distracted with an error until after interacti
94
95
</style>
95
96
96
97
<script>
97
- function Controller($scope) {
98
- $scope.master = {};
98
+ angular.module('formExample', [])
99
+ .controller('ExampleController', ['$scope', function($scope) {
100
+ $scope.master = {};
99
101
100
- $scope.update = function(user) {
101
- $scope.master = angular.copy(user);
102
- };
102
+ $scope.update = function(user) {
103
+ $scope.master = angular.copy(user);
104
+ };
103
105
104
- $scope.reset = function() {
105
- $scope.user = angular.copy($scope.master);
106
- };
106
+ $scope.reset = function() {
107
+ $scope.user = angular.copy($scope.master);
108
+ };
107
109
108
- $scope.reset();
109
- }
110
+ $scope.reset();
111
+ }]);
110
112
</script>
111
113
</file>
112
114
</example>
@@ -132,7 +134,7 @@ This allows us to extend the above example with these features:
132
134
- SAVE button is enabled only if form has some changes and is valid
133
135
- custom error messages for `user.email` and `user.agree`
134
136
135
- <example>
137
+ <example module="formExample" >
136
138
<file name="index.html">
137
139
<div ng-controller="Controller">
138
140
<form name="form" class="css-form" novalidate>
@@ -161,23 +163,24 @@ This allows us to extend the above example with these features:
161
163
</file>
162
164
163
165
<file name="script.js">
164
- function Controller($scope) {
165
- $scope.master = {};
166
+ angular.module('formExample', [])
167
+ .controller('ExampleController', ['$scope', function($scope) {
168
+ $scope.master = {};
166
169
167
- $scope.update = function(user) {
168
- $scope.master = angular.copy(user);
169
- };
170
+ $scope.update = function(user) {
171
+ $scope.master = angular.copy(user);
172
+ };
170
173
171
- $scope.reset = function() {
172
- $scope.user = angular.copy($scope.master);
173
- };
174
+ $scope.reset = function() {
175
+ $scope.user = angular.copy($scope.master);
176
+ };
174
177
175
- $scope.isUnchanged = function(user) {
176
- return angular.equals(user, $scope.master);
177
- };
178
+ $scope.isUnchanged = function(user) {
179
+ return angular.equals(user, $scope.master);
180
+ };
178
181
179
- $scope.reset();
180
- }
182
+ $scope.reset();
183
+ }]);
181
184
</file>
182
185
</example>
183
186
@@ -196,12 +199,12 @@ and validation, add "default" as one of the specified events.
196
199
197
200
I.e. `ng-model-options="{ updateOn: 'default blur' }"`
198
201
199
- The following example shows how to override immediate updates. Changes on the inputs within the form will update the model
202
+ The following example shows how to override immediate updates. Changes on the inputs within the form will update the model
200
203
only when the control loses focus (blur event).
201
204
202
- <example>
205
+ <example module="customTriggerExample" >
203
206
<file name="index.html">
204
- <div ng-controller="ControllerUpdateOn ">
207
+ <div ng-controller="ExampleController ">
205
208
<form>
206
209
Name:
207
210
<input type="text" ng-model="user.name" ng-model-options="{ updateOn: 'blur' }" /><br />
@@ -212,9 +215,10 @@ only when the control loses focus (blur event).
212
215
</div>
213
216
</file>
214
217
<file name="script.js">
215
- function ControllerUpdateOn($scope) {
216
- $scope.user = {};
217
- }
218
+ angular.module('customTriggerExample', [])
219
+ .controller('ExampleController', ['$scope', function($scope) {
220
+ $scope.user = {};
221
+ }]);
218
222
</file>
219
223
</example>
220
224
@@ -240,9 +244,9 @@ overridden.
240
244
241
245
This example shows how to debounce model changes. Model will be updated only 250 milliseconds after last change.
242
246
243
- <example>
247
+ <example module="debounceExample" >
244
248
<file name="index.html">
245
- <div ng-controller="ControllerUpdateOn ">
249
+ <div ng-controller="ExampleController ">
246
250
<form>
247
251
Name:
248
252
<input type="text" ng-model="user.name" ng-model-options="{ debounce: 250 }" /><br />
@@ -251,9 +255,10 @@ This example shows how to debounce model changes. Model will be updated only 250
251
255
</div>
252
256
</file>
253
257
<file name="script.js">
254
- function ControllerUpdateOn($scope) {
255
- $scope.user = {};
256
- }
258
+ angular.module('debounceExample', [])
259
+ .controller('ExampleController', ['$scope', function($scope) {
260
+ $scope.user = {};
261
+ }]);
257
262
</file>
258
263
</example>
259
264
0 commit comments