@@ -454,10 +454,12 @@ var formDirectiveFactory = function(isNgForm) {
454
454
name : 'form' ,
455
455
restrict : isNgForm ? 'EAC' : 'E' ,
456
456
controller : FormController ,
457
- compile : function ngFormCompile ( formElement ) {
457
+ compile : function ngFormCompile ( formElement , attr ) {
458
458
// Setup initial state of the control
459
459
formElement . addClass ( PRISTINE_CLASS ) . addClass ( VALID_CLASS ) ;
460
460
461
+ var nameAttr = attr . name ? 'name' : ( isNgForm && attr . ngForm ? 'ngForm' : false ) ;
462
+
461
463
return {
462
464
pre : function ngFormPreLink ( scope , formElement , attr , controller ) {
463
465
// if `action` attr is not present on the form, prevent the default action (submission)
@@ -488,23 +490,21 @@ var formDirectiveFactory = function(isNgForm) {
488
490
} ) ;
489
491
}
490
492
491
- var parentFormCtrl = controller . $$parentForm ,
492
- alias = controller . $name ;
493
-
494
- if ( alias ) {
495
- setter ( scope , alias , controller , alias ) ;
496
- attr . $observe ( attr . name ? 'name' : 'ngForm' , function ( newValue ) {
497
- if ( alias === newValue ) return ;
498
- setter ( scope , alias , undefined , alias ) ;
499
- alias = newValue ;
500
- setter ( scope , alias , controller , alias ) ;
501
- parentFormCtrl . $$renameControl ( controller , alias ) ;
493
+ var parentFormCtrl = controller . $$parentForm ;
494
+
495
+ if ( nameAttr ) {
496
+ setter ( scope , controller . $name , controller , controller . $name ) ;
497
+ attr . $observe ( nameAttr , function ( newValue ) {
498
+ if ( controller . $name === newValue ) return ;
499
+ setter ( scope , controller . $name , undefined , controller . $name ) ;
500
+ parentFormCtrl . $$renameControl ( controller , newValue ) ;
501
+ setter ( scope , controller . $name , controller , controller . $name ) ;
502
502
} ) ;
503
503
}
504
504
formElement . on ( '$destroy' , function ( ) {
505
505
parentFormCtrl . $removeControl ( controller ) ;
506
- if ( alias ) {
507
- setter ( scope , alias , undefined , alias ) ;
506
+ if ( nameAttr ) {
507
+ setter ( scope , attr [ nameAttr ] , undefined , controller . $name ) ;
508
508
}
509
509
extend ( controller , nullFormCtrl ) ; //stop propagating child destruction handlers upwards
510
510
} ) ;
0 commit comments