@@ -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>
@@ -67,9 +68,9 @@ The following example uses the CSS to display validity of each form control.
67
68
In the example both `user.name` and `user.email` are required, but are rendered with red background only when they are dirty.
68
69
This ensures that the user is not distracted with an error until after interacting with the control, and failing to satisfy its validity.
69
70
70
- <example>
71
+ <example module="formExample" >
71
72
<file name="index.html">
72
- <div ng-controller="Controller ">
73
+ <div ng-controller="ExampleController ">
73
74
<form novalidate class="css-form">
74
75
Name:
75
76
<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
92
93
</style>
93
94
94
95
<script>
95
- function Controller($scope) {
96
- $scope.master = {};
96
+ angular.module('formExample', [])
97
+ .controller('ExampleController', ['$scope', function($scope) {
98
+ $scope.master = {};
97
99
98
- $scope.update = function(user) {
99
- $scope.master = angular.copy(user);
100
- };
100
+ $scope.update = function(user) {
101
+ $scope.master = angular.copy(user);
102
+ };
101
103
102
- $scope.reset = function() {
103
- $scope.user = angular.copy($scope.master);
104
- };
104
+ $scope.reset = function() {
105
+ $scope.user = angular.copy($scope.master);
106
+ };
105
107
106
- $scope.reset();
107
- }
108
+ $scope.reset();
109
+ }]);
108
110
</script>
109
111
</file>
110
112
</example>
@@ -130,7 +132,7 @@ This allows us to extend the above example with these features:
130
132
- SAVE button is enabled only if form has some changes and is valid
131
133
- custom error messages for `user.email` and `user.agree`
132
134
133
- <example>
135
+ <example module="formExample" >
134
136
<file name="index.html">
135
137
<div ng-controller="Controller">
136
138
<form name="form" class="css-form" novalidate>
@@ -159,23 +161,24 @@ This allows us to extend the above example with these features:
159
161
</file>
160
162
161
163
<file name="script.js">
162
- function Controller($scope) {
163
- $scope.master = {};
164
+ angular.module('formExample', [])
165
+ .controller('ExampleController', ['$scope', function($scope) {
166
+ $scope.master = {};
164
167
165
- $scope.update = function(user) {
166
- $scope.master = angular.copy(user);
167
- };
168
+ $scope.update = function(user) {
169
+ $scope.master = angular.copy(user);
170
+ };
168
171
169
- $scope.reset = function() {
170
- $scope.user = angular.copy($scope.master);
171
- };
172
+ $scope.reset = function() {
173
+ $scope.user = angular.copy($scope.master);
174
+ };
172
175
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
+ };
176
179
177
- $scope.reset();
178
- }
180
+ $scope.reset();
181
+ }]);
179
182
</file>
180
183
</example>
181
184
0 commit comments