From de127109f925a6d67621e40a2bc4e9e954373855 Mon Sep 17 00:00:00 2001 From: Kara Erickson Date: Fri, 24 Jun 2016 13:37:42 -0700 Subject: [PATCH] feat(forms): make valueChanges and statusChanges available on abstract control directives --- .../src/directives/abstract_control_directive.ts | 10 ++++++++++ modules/@angular/forms/test/directives_spec.ts | 12 ++++++++++++ modules/@angular/forms/test/integration_spec.ts | 4 ++-- tools/public_api_guard/forms/index.d.ts | 2 ++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/modules/@angular/forms/src/directives/abstract_control_directive.ts b/modules/@angular/forms/src/directives/abstract_control_directive.ts index 1f484f1d66..a10adabcf9 100644 --- a/modules/@angular/forms/src/directives/abstract_control_directive.ts +++ b/modules/@angular/forms/src/directives/abstract_control_directive.ts @@ -6,11 +6,13 @@ * found in the LICENSE file at https://angular.io/license */ +import {Observable} from '../facade/async'; import {unimplemented} from '../facade/exceptions'; import {isPresent} from '../facade/lang'; import {AbstractControl} from '../model'; + /** * Base class for control directives. * @@ -37,5 +39,13 @@ export abstract class AbstractControlDirective { get untouched(): boolean { return isPresent(this.control) ? this.control.untouched : null; } + get statusChanges(): Observable { + return isPresent(this.control) ? this.control.statusChanges : null; + } + + get valueChanges(): Observable { + return isPresent(this.control) ? this.control.valueChanges : null; + } + get path(): string[] { return null; } } diff --git a/modules/@angular/forms/test/directives_spec.ts b/modules/@angular/forms/test/directives_spec.ts index 9219e3533e..42883f26e2 100644 --- a/modules/@angular/forms/test/directives_spec.ts +++ b/modules/@angular/forms/test/directives_spec.ts @@ -141,6 +141,8 @@ export function main() { expect(form.dirty).toBe(formModel.dirty); expect(form.touched).toBe(formModel.touched); expect(form.untouched).toBe(formModel.untouched); + expect(form.statusChanges).toBe(formModel.statusChanges); + expect(form.valueChanges).toBe(formModel.valueChanges); }); describe('addControl', () => { @@ -295,6 +297,8 @@ export function main() { expect(form.dirty).toBe(formModel.dirty); expect(form.touched).toBe(formModel.touched); expect(form.untouched).toBe(formModel.untouched); + expect(form.statusChanges).toBe(formModel.statusChanges); + expect(form.valueChanges).toBe(formModel.valueChanges); }); describe('addControl & addFormGroup', () => { @@ -367,6 +371,8 @@ export function main() { expect(controlGroupDir.dirty).toBe(formModel.dirty); expect(controlGroupDir.touched).toBe(formModel.touched); expect(controlGroupDir.untouched).toBe(formModel.untouched); + expect(controlGroupDir.statusChanges).toBe(formModel.statusChanges); + expect(controlGroupDir.valueChanges).toBe(formModel.valueChanges); }); }); @@ -382,6 +388,8 @@ export function main() { expect(controlDir.dirty).toBe(control.dirty); expect(controlDir.touched).toBe(control.touched); expect(controlDir.untouched).toBe(control.untouched); + expect(controlDir.statusChanges).toBe(control.statusChanges); + expect(controlDir.valueChanges).toBe(control.valueChanges); }; beforeEach(() => { @@ -431,6 +439,8 @@ export function main() { expect(ngModel.dirty).toBe(control.dirty); expect(ngModel.touched).toBe(control.touched); expect(ngModel.untouched).toBe(control.untouched); + expect(ngModel.statusChanges).toBe(control.statusChanges); + expect(ngModel.valueChanges).toBe(control.valueChanges); }); it('should set up validator', fakeAsync(() => { @@ -469,6 +479,8 @@ export function main() { expect(controlNameDir.dirty).toBe(formModel.dirty); expect(controlNameDir.touched).toBe(formModel.touched); expect(controlNameDir.untouched).toBe(formModel.untouched); + expect(controlNameDir.statusChanges).toBe(formModel.statusChanges); + expect(controlNameDir.valueChanges).toBe(formModel.valueChanges); }); }); }); diff --git a/modules/@angular/forms/test/integration_spec.ts b/modules/@angular/forms/test/integration_spec.ts index 179767671d..b05e244800 100644 --- a/modules/@angular/forms/test/integration_spec.ts +++ b/modules/@angular/forms/test/integration_spec.ts @@ -1247,10 +1247,10 @@ export function main() { let formValue: Object; ObservableWrapper.subscribe( - form.form.statusChanges, (status: string) => { formValidity = status; }); + form.statusChanges, (status: string) => { formValidity = status; }); ObservableWrapper.subscribe( - form.form.valueChanges, (value: string) => { formValue = value; }); + form.valueChanges, (value: string) => { formValue = value; }); tick(); diff --git a/tools/public_api_guard/forms/index.d.ts b/tools/public_api_guard/forms/index.d.ts index 1ae5353812..25272cf3c9 100644 --- a/tools/public_api_guard/forms/index.d.ts +++ b/tools/public_api_guard/forms/index.d.ts @@ -50,10 +50,12 @@ export declare abstract class AbstractControlDirective { }; path: string[]; pristine: boolean; + statusChanges: Observable; touched: boolean; untouched: boolean; valid: boolean; value: any; + valueChanges: Observable; } export declare class CheckboxControlValueAccessor implements ControlValueAccessor {