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

Skip to content

Commit 3ecac62

Browse files
committed
docs(guide/forms): update examples to use modules
1 parent c646102 commit 3ecac62

File tree

1 file changed

+41
-38
lines changed

1 file changed

+41
-38
lines changed

docs/content/guide/forms.ngdoc

Lines changed: 41 additions & 38 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>
@@ -67,9 +68,9 @@ The following example uses the CSS to display validity of each form control.
6768
In the example both `user.name` and `user.email` are required, but are rendered with red background only when they are dirty.
6869
This ensures that the user is not distracted with an error until after interacting with the control, and failing to satisfy its validity.
6970

70-
<example>
71+
<example module="formExample">
7172
<file name="index.html">
72-
<div ng-controller="Controller">
73+
<div ng-controller="ExampleController">
7374
<form novalidate class="css-form">
7475
Name:
7576
<input type="text" ng-model="user.name" required /><br />
@@ -92,19 +93,20 @@ This ensures that the user is not distracted with an error until after interacti
9293
</style>
9394

9495
<script>
95-
function Controller($scope) {
96-
$scope.master = {};
96+
angular.module('formExample', [])
97+
.controller('ExampleController', ['$scope', function($scope) {
98+
$scope.master = {};
9799

98-
$scope.update = function(user) {
99-
$scope.master = angular.copy(user);
100-
};
100+
$scope.update = function(user) {
101+
$scope.master = angular.copy(user);
102+
};
101103

102-
$scope.reset = function() {
103-
$scope.user = angular.copy($scope.master);
104-
};
104+
$scope.reset = function() {
105+
$scope.user = angular.copy($scope.master);
106+
};
105107

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

133-
<example>
135+
<example module="formExample">
134136
<file name="index.html">
135137
<div ng-controller="Controller">
136138
<form name="form" class="css-form" novalidate>
@@ -159,23 +161,24 @@ This allows us to extend the above example with these features:
159161
</file>
160162

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

165-
$scope.update = function(user) {
166-
$scope.master = angular.copy(user);
167-
};
168+
$scope.update = function(user) {
169+
$scope.master = angular.copy(user);
170+
};
168171

169-
$scope.reset = function() {
170-
$scope.user = angular.copy($scope.master);
171-
};
172+
$scope.reset = function() {
173+
$scope.user = angular.copy($scope.master);
174+
};
172175

173-
$scope.isUnchanged = function(user) {
174-
return angular.equals(user, $scope.master);
175-
};
176+
$scope.isUnchanged = function(user) {
177+
return angular.equals(user, $scope.master);
178+
};
176179

177-
$scope.reset();
178-
}
180+
$scope.reset();
181+
}]);
179182
</file>
180183
</example>
181184

0 commit comments

Comments
 (0)