Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 470ad11

Browse files
committed
docs(guide/forms): update examples to use modules
1 parent 9caff0d commit 470ad11

File tree

1 file changed

+54
-49
lines changed

1 file changed

+54
-49
lines changed

docs/content/guide/forms.ngdoc

Lines changed: 54 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ The key directive in understanding two-way data-binding is {@link ng.directive:n
1616
The `ngModel` directive provides the two-way data-binding by synchronizing the model to the view, as well as view to the model.
1717
In addition it provides an {@link ngModel.NgModelController API} for other directives to augment its behavior.
1818

19-
<example>
19+
<example module="formExample">
2020
<file name="index.html">
21-
<div ng-controller="Controller">
21+
<div ng-controller="ExampleController">
2222
<form novalidate class="simple-form">
2323
Name: <input type="text" ng-model="user.name" /><br />
2424
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
3232
</div>
3333

3434
<script>
35-
function Controller($scope) {
36-
$scope.master = {};
35+
angular.module('formExample', [])
36+
.controller('ExampleController', ['$scope', function($scope) {
37+
$scope.master = {};
3738

38-
$scope.update = function(user) {
39-
$scope.master = angular.copy(user);
40-
};
39+
$scope.update = function(user) {
40+
$scope.master = angular.copy(user);
41+
};
4142

42-
$scope.reset = function() {
43-
$scope.user = angular.copy($scope.master);
44-
};
43+
$scope.reset = function() {
44+
$scope.user = angular.copy($scope.master);
45+
};
4546

46-
$scope.reset();
47-
}
47+
$scope.reset();
48+
}]);
4849
</script>
4950
</file>
5051
</example>
@@ -69,9 +70,9 @@ The following example uses the CSS to display validity of each form control.
6970
In the example both `user.name` and `user.email` are required, but are rendered with red background only when they are dirty.
7071
This ensures that the user is not distracted with an error until after interacting with the control, and failing to satisfy its validity.
7172

72-
<example>
73+
<example module="formExample">
7374
<file name="index.html">
74-
<div ng-controller="Controller">
75+
<div ng-controller="ExampleController">
7576
<form novalidate class="css-form">
7677
Name:
7778
<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
9495
</style>
9596

9697
<script>
97-
function Controller($scope) {
98-
$scope.master = {};
98+
angular.module('formExample', [])
99+
.controller('ExampleController', ['$scope', function($scope) {
100+
$scope.master = {};
99101

100-
$scope.update = function(user) {
101-
$scope.master = angular.copy(user);
102-
};
102+
$scope.update = function(user) {
103+
$scope.master = angular.copy(user);
104+
};
103105

104-
$scope.reset = function() {
105-
$scope.user = angular.copy($scope.master);
106-
};
106+
$scope.reset = function() {
107+
$scope.user = angular.copy($scope.master);
108+
};
107109

108-
$scope.reset();
109-
}
110+
$scope.reset();
111+
}]);
110112
</script>
111113
</file>
112114
</example>
@@ -132,7 +134,7 @@ This allows us to extend the above example with these features:
132134
- SAVE button is enabled only if form has some changes and is valid
133135
- custom error messages for `user.email` and `user.agree`
134136

135-
<example>
137+
<example module="formExample">
136138
<file name="index.html">
137139
<div ng-controller="Controller">
138140
<form name="form" class="css-form" novalidate>
@@ -161,23 +163,24 @@ This allows us to extend the above example with these features:
161163
</file>
162164

163165
<file name="script.js">
164-
function Controller($scope) {
165-
$scope.master = {};
166+
angular.module('formExample', [])
167+
.controller('ExampleController', ['$scope', function($scope) {
168+
$scope.master = {};
166169

167-
$scope.update = function(user) {
168-
$scope.master = angular.copy(user);
169-
};
170+
$scope.update = function(user) {
171+
$scope.master = angular.copy(user);
172+
};
170173

171-
$scope.reset = function() {
172-
$scope.user = angular.copy($scope.master);
173-
};
174+
$scope.reset = function() {
175+
$scope.user = angular.copy($scope.master);
176+
};
174177

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+
};
178181

179-
$scope.reset();
180-
}
182+
$scope.reset();
183+
}]);
181184
</file>
182185
</example>
183186

@@ -196,12 +199,12 @@ and validation, add "default" as one of the specified events.
196199

197200
I.e. `ng-model-options="{ updateOn: 'default blur' }"`
198201

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
200203
only when the control loses focus (blur event).
201204

202-
<example>
205+
<example module="customTriggerExample">
203206
<file name="index.html">
204-
<div ng-controller="ControllerUpdateOn">
207+
<div ng-controller="ExampleController">
205208
<form>
206209
Name:
207210
<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).
212215
</div>
213216
</file>
214217
<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+
}]);
218222
</file>
219223
</example>
220224

@@ -240,9 +244,9 @@ overridden.
240244

241245
This example shows how to debounce model changes. Model will be updated only 250 milliseconds after last change.
242246

243-
<example>
247+
<example module="debounceExample">
244248
<file name="index.html">
245-
<div ng-controller="ControllerUpdateOn">
249+
<div ng-controller="ExampleController">
246250
<form>
247251
Name:
248252
<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
251255
</div>
252256
</file>
253257
<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+
}]);
257262
</file>
258263
</example>
259264

0 commit comments

Comments
 (0)