11import { CONST_EXPR } from 'angular2/src/facade/lang' ;
22import { EventEmitter , ObservableWrapper } from 'angular2/src/facade/async' ;
3- import { List , StringMapWrapper , StringMap } from 'angular2/src/facade/collection' ;
3+ import { List , StringMap } from 'angular2/src/facade/collection' ;
44
55import { Directive , LifecycleEvent , Query , QueryList } from 'angular2/angular2' ;
66import { forwardRef , Ancestor , Binding , Inject } from 'angular2/di' ;
77
88import { ControlContainer } from './control_container' ;
99import { NgControl } from './ng_control' ;
1010import { NgValidator } from './validators' ;
11- import { controlPath , composeNgValidator } from './shared' ;
11+ import { controlPath , composeNgValidator , isPropertyUpdated } from './shared' ;
1212import { Control } from '../model' ;
1313
1414const controlNameBinding =
@@ -82,6 +82,7 @@ export class NgControlName extends NgControl {
8282 _parent : ControlContainer ;
8383 update = new EventEmitter ( ) ;
8484 model : any ;
85+ viewModel : any ;
8586 ngValidators : QueryList < NgValidator > ;
8687 _added = false ;
8788
@@ -98,14 +99,18 @@ export class NgControlName extends NgControl {
9899 this . formDirective . addControl ( this ) ;
99100 this . _added = true ;
100101 }
101- if ( StringMapWrapper . contains ( c , "model" ) ) {
102+ if ( isPropertyUpdated ( c , this . viewModel ) ) {
103+ this . viewModel = this . model ;
102104 this . formDirective . updateModel ( this , this . model ) ;
103105 }
104106 }
105107
106108 onDestroy ( ) { this . formDirective . removeControl ( this ) ; }
107109
108- viewToModelUpdate ( newValue : any ) : void { ObservableWrapper . callNext ( this . update , newValue ) ; }
110+ viewToModelUpdate ( newValue : any ) : void {
111+ this . viewModel = newValue ;
112+ ObservableWrapper . callNext ( this . update , newValue ) ;
113+ }
109114
110115 get path ( ) : List < string > { return controlPath ( this . name , this . _parent ) ; }
111116
0 commit comments