@@ -31,10 +31,10 @@ var nullFormCtrl = {
31
31
* of `FormController`.
32
32
*
33
33
*/
34
- FormController . $inject = [ 'name' , ' $element', '$attrs' ] ;
35
- function FormController ( name , element , attrs ) {
34
+ FormController . $inject = [ '$element' , '$attrs' ] ;
35
+ function FormController ( element , attrs ) {
36
36
var form = this ,
37
- parentForm = element . parent ( ) . inheritedData ( '$formController ') || nullFormCtrl ,
37
+ parentForm = element . parent ( ) . controller ( 'form ') || nullFormCtrl ,
38
38
invalidCount = 0 , // used to easily determine if we are valid
39
39
errors = form . $error = { } ;
40
40
@@ -45,9 +45,6 @@ function FormController(name, element, attrs) {
45
45
form . $valid = true ;
46
46
form . $invalid = false ;
47
47
48
- // publish the form into scope
49
- name ( this ) ;
50
-
51
48
parentForm . $addControl ( form ) ;
52
49
53
50
// Setup initial state of the control
@@ -130,9 +127,24 @@ function FormController(name, element, attrs) {
130
127
131
128
132
129
/**
130
+ * @ngdoc directive
131
+ * @name angular.module.ng.$compileProvider.directive.ng-form
132
+ * @restrict EAC
133
+ *
134
+ * @description
135
+ * Nestable alias of {@link angular.module.ng.$compileProvider.directive.form `form`} directive. HTML
136
+ * does not allow nesting of form elements. It is useful to nest forms, for example if the validity of a
137
+ * sub-group of controls needs to be determined.
138
+ *
139
+ * @param {string= } ng-form|name Name of the form. If specified, the form controller will be published into
140
+ * related scope, under this name.
141
+ *
142
+ */
143
+
144
+ /**
133
145
* @ngdoc directive
134
146
* @name angular.module.ng.$compileProvider.directive.form
135
- * @restrict EA
147
+ * @restrict E
136
148
*
137
149
* @description
138
150
* Directive that instantiates
@@ -141,12 +153,12 @@ function FormController(name, element, attrs) {
141
153
* If `name` attribute is specified, the form controller is published onto the current scope under
142
154
* this name.
143
155
*
144
- * # Alias: `ng-form`
156
+ * # Alias: { @link angular.module.ng.$compileProvider.directive.ng-form `ng-form`}
145
157
*
146
158
* In angular forms can be nested. This means that the outer form is valid when all of the child
147
159
* forms are valid as well. However browsers do not allow nesting of `<form>` elements, for this
148
- * reason angular provides `<ng -form>` alias which behaves identical to `< form>` but allows
149
- * element nesting.
160
+ * reason angular provides { @link angular.module.ng.$compileProvider.directive.ng -form `ng- form`} alias
161
+ * which behaves identical to `<form>` but allows form nesting.
150
162
*
151
163
*
152
164
* # CSS classes
@@ -218,25 +230,31 @@ function FormController(name, element, attrs) {
218
230
</doc:scenario>
219
231
</doc:example>
220
232
*/
221
- var formDirectiveDev = {
233
+ var formDirectiveDir = {
222
234
name : 'form' ,
223
235
restrict : 'E' ,
224
- inject : {
225
- name : 'accessor'
226
- } ,
227
236
controller : FormController ,
228
237
compile : function ( ) {
229
238
return {
230
239
pre : function ( scope , formElement , attr , controller ) {
231
- formElement . bind ( 'submit' , function ( event ) {
232
- if ( ! attr . action ) event . preventDefault ( ) ;
233
- } ) ;
240
+ if ( ! attr . action ) {
241
+ formElement . bind ( 'submit' , function ( event ) {
242
+ event . preventDefault ( ) ;
243
+ } ) ;
244
+ }
245
+
246
+ var parentFormCtrl = formElement . parent ( ) . controller ( 'form' ) ,
247
+ alias = attr . name || attr . ngForm ;
234
248
235
- var parentFormCtrl = formElement . parent ( ) . inheritedData ( '$formController' ) ;
249
+ if ( alias ) {
250
+ scope [ alias ] = controller ;
251
+ }
236
252
if ( parentFormCtrl ) {
237
253
formElement . bind ( '$destroy' , function ( ) {
238
254
parentFormCtrl . $removeControl ( controller ) ;
239
- if ( attr . name ) delete scope [ attr . name ] ;
255
+ if ( alias ) {
256
+ scope [ alias ] = undefined ;
257
+ }
240
258
extend ( controller , nullFormCtrl ) ; //stop propagating child destruction handlers upwards
241
259
} ) ;
242
260
}
@@ -245,5 +263,5 @@ var formDirectiveDev = {
245
263
}
246
264
} ;
247
265
248
- var formDirective = valueFn ( formDirectiveDev ) ;
249
- var ngFormDirective = valueFn ( extend ( copy ( formDirectiveDev ) , { restrict :'EAC' } ) ) ;
266
+ var formDirective = valueFn ( formDirectiveDir ) ;
267
+ var ngFormDirective = valueFn ( extend ( copy ( formDirectiveDir ) , { restrict : 'EAC' } ) ) ;
0 commit comments