File tree Expand file tree Collapse file tree
src/core/forms/directives Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { AbstractControl } from '../model' ;
2+ import { isPresent } from 'angular2/src/core/facade/lang' ;
23
34export class AbstractControlDirective {
45 get control ( ) : AbstractControl { return null ; }
56
6- get value ( ) : any { return this . control . value ; }
7+ get value ( ) : any { return isPresent ( this . control ) ? this . control . value : null ; }
78
8- get valid ( ) : boolean { return this . control . valid ; }
9+ get valid ( ) : boolean { return isPresent ( this . control ) ? this . control . valid : null ; }
910
10- get errors ( ) : StringMap < string , any > { return this . control . errors ; }
11+ get errors ( ) : StringMap < string , any > {
12+ return isPresent ( this . control ) ? this . control . errors : null ;
13+ }
1114
12- get pristine ( ) : boolean { return this . control . pristine ; }
15+ get pristine ( ) : boolean { return isPresent ( this . control ) ? this . control . pristine : null ; }
1316
14- get dirty ( ) : boolean { return this . control . dirty ; }
17+ get dirty ( ) : boolean { return isPresent ( this . control ) ? this . control . dirty : null ; }
1518
16- get touched ( ) : boolean { return this . control . touched ; }
19+ get touched ( ) : boolean { return isPresent ( this . control ) ? this . control . touched : null ; }
1720
18- get untouched ( ) : boolean { return this . control . untouched ; }
21+ get untouched ( ) : boolean { return isPresent ( this . control ) ? this . control . untouched : null ; }
1922}
Original file line number Diff line number Diff line change @@ -800,6 +800,19 @@ export function main() {
800800 rootTC . detectChanges ( ) ;
801801 expect ( input . value ) . toEqual ( "aa" ) ;
802802 } ) ) ) ;
803+ it ( "should not crash when validity is checked from a binding" ,
804+ inject ( [ TestComponentBuilder ] , fakeAsync ( ( tcb : TestComponentBuilder ) => {
805+ // {{x.valid}} used to crash because valid() tried to read a property
806+ // from form.control before it was set. This test verifies this bug is
807+ // fixed.
808+ var t = `<form><div ng-control-group="x" #x="form">
809+ <input type="text" ng-control="test"></div>{{x.valid}}</form>` ;
810+ var rootTC : RootTestComponent ;
811+ tcb . overrideTemplate ( MyComp , t ) . createAsync ( MyComp ) . then (
812+ ( root ) => { rootTC = root ; } ) ;
813+ tick ( ) ;
814+ rootTC . detectChanges ( ) ;
815+ } ) ) ) ;
803816 } ) ;
804817 } ) ;
805818}
You can’t perform that action at this time.
0 commit comments