Skip to content

Commit de12710

Browse files
committed
feat(forms): make valueChanges and statusChanges available on abstract control directives
1 parent 8320898 commit de12710

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

modules/@angular/forms/src/directives/abstract_control_directive.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {Observable} from '../facade/async';
910
import {unimplemented} from '../facade/exceptions';
1011
import {isPresent} from '../facade/lang';
1112
import {AbstractControl} from '../model';
1213

1314

15+
1416
/**
1517
* Base class for control directives.
1618
*
@@ -37,5 +39,13 @@ export abstract class AbstractControlDirective {
3739

3840
get untouched(): boolean { return isPresent(this.control) ? this.control.untouched : null; }
3941

42+
get statusChanges(): Observable<any> {
43+
return isPresent(this.control) ? this.control.statusChanges : null;
44+
}
45+
46+
get valueChanges(): Observable<any> {
47+
return isPresent(this.control) ? this.control.valueChanges : null;
48+
}
49+
4050
get path(): string[] { return null; }
4151
}

modules/@angular/forms/test/directives_spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ export function main() {
141141
expect(form.dirty).toBe(formModel.dirty);
142142
expect(form.touched).toBe(formModel.touched);
143143
expect(form.untouched).toBe(formModel.untouched);
144+
expect(form.statusChanges).toBe(formModel.statusChanges);
145+
expect(form.valueChanges).toBe(formModel.valueChanges);
144146
});
145147

146148
describe('addControl', () => {
@@ -295,6 +297,8 @@ export function main() {
295297
expect(form.dirty).toBe(formModel.dirty);
296298
expect(form.touched).toBe(formModel.touched);
297299
expect(form.untouched).toBe(formModel.untouched);
300+
expect(form.statusChanges).toBe(formModel.statusChanges);
301+
expect(form.valueChanges).toBe(formModel.valueChanges);
298302
});
299303

300304
describe('addControl & addFormGroup', () => {
@@ -367,6 +371,8 @@ export function main() {
367371
expect(controlGroupDir.dirty).toBe(formModel.dirty);
368372
expect(controlGroupDir.touched).toBe(formModel.touched);
369373
expect(controlGroupDir.untouched).toBe(formModel.untouched);
374+
expect(controlGroupDir.statusChanges).toBe(formModel.statusChanges);
375+
expect(controlGroupDir.valueChanges).toBe(formModel.valueChanges);
370376
});
371377
});
372378

@@ -382,6 +388,8 @@ export function main() {
382388
expect(controlDir.dirty).toBe(control.dirty);
383389
expect(controlDir.touched).toBe(control.touched);
384390
expect(controlDir.untouched).toBe(control.untouched);
391+
expect(controlDir.statusChanges).toBe(control.statusChanges);
392+
expect(controlDir.valueChanges).toBe(control.valueChanges);
385393
};
386394

387395
beforeEach(() => {
@@ -431,6 +439,8 @@ export function main() {
431439
expect(ngModel.dirty).toBe(control.dirty);
432440
expect(ngModel.touched).toBe(control.touched);
433441
expect(ngModel.untouched).toBe(control.untouched);
442+
expect(ngModel.statusChanges).toBe(control.statusChanges);
443+
expect(ngModel.valueChanges).toBe(control.valueChanges);
434444
});
435445

436446
it('should set up validator', fakeAsync(() => {
@@ -469,6 +479,8 @@ export function main() {
469479
expect(controlNameDir.dirty).toBe(formModel.dirty);
470480
expect(controlNameDir.touched).toBe(formModel.touched);
471481
expect(controlNameDir.untouched).toBe(formModel.untouched);
482+
expect(controlNameDir.statusChanges).toBe(formModel.statusChanges);
483+
expect(controlNameDir.valueChanges).toBe(formModel.valueChanges);
472484
});
473485
});
474486
});

modules/@angular/forms/test/integration_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,10 +1247,10 @@ export function main() {
12471247
let formValue: Object;
12481248

12491249
ObservableWrapper.subscribe(
1250-
form.form.statusChanges, (status: string) => { formValidity = status; });
1250+
form.statusChanges, (status: string) => { formValidity = status; });
12511251

12521252
ObservableWrapper.subscribe(
1253-
form.form.valueChanges, (value: string) => { formValue = value; });
1253+
form.valueChanges, (value: string) => { formValue = value; });
12541254

12551255
tick();
12561256

tools/public_api_guard/forms/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ export declare abstract class AbstractControlDirective {
5050
};
5151
path: string[];
5252
pristine: boolean;
53+
statusChanges: Observable<any>;
5354
touched: boolean;
5455
untouched: boolean;
5556
valid: boolean;
5657
value: any;
58+
valueChanges: Observable<any>;
5759
}
5860

5961
export declare class CheckboxControlValueAccessor implements ControlValueAccessor {

0 commit comments

Comments
 (0)