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

62 lines
2.0 KiB
TypeScript
Raw Normal View History

/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {Observable} from '../facade/async';
import {AbstractControl} from '../model';
2016-06-08 15:36:24 -07:00
/**
* Base class for control directives.
*
* Only used internally in the forms module.
*
* @stable
2016-06-08 15:36:24 -07:00
*/
export abstract class AbstractControlDirective {
get control(): AbstractControl { throw new Error('unimplemented'); }
2016-06-08 15:36:24 -07:00
2016-11-11 10:47:34 -08:00
get value(): any { return this.control ? this.control.value : null; }
2016-06-08 15:36:24 -07:00
2016-11-11 10:47:34 -08:00
get valid(): boolean { return this.control ? this.control.valid : null; }
2016-06-08 15:36:24 -07:00
2016-11-11 10:47:34 -08:00
get invalid(): boolean { return this.control ? this.control.invalid : null; }
2016-11-11 10:47:34 -08:00
get pending(): boolean { return this.control ? this.control.pending : null; }
2016-11-11 10:47:34 -08:00
get errors(): {[key: string]: any} { return this.control ? this.control.errors : null; }
2016-06-08 15:36:24 -07:00
2016-11-11 10:47:34 -08:00
get pristine(): boolean { return this.control ? this.control.pristine : null; }
2016-06-08 15:36:24 -07:00
2016-11-11 10:47:34 -08:00
get dirty(): boolean { return this.control ? this.control.dirty : null; }
2016-06-08 15:36:24 -07:00
2016-11-11 10:47:34 -08:00
get touched(): boolean { return this.control ? this.control.touched : null; }
2016-06-08 15:36:24 -07:00
2016-11-11 10:47:34 -08:00
get untouched(): boolean { return this.control ? this.control.untouched : null; }
2016-06-08 15:36:24 -07:00
2016-11-11 10:47:34 -08:00
get disabled(): boolean { return this.control ? this.control.disabled : null; }
2016-11-11 10:47:34 -08:00
get enabled(): boolean { return this.control ? this.control.enabled : null; }
2016-11-11 10:47:34 -08:00
get statusChanges(): Observable<any> { return this.control ? this.control.statusChanges : null; }
2016-11-11 10:47:34 -08:00
get valueChanges(): Observable<any> { return this.control ? this.control.valueChanges : null; }
2016-06-08 15:36:24 -07:00
get path(): string[] { return null; }
reset(value: any = undefined): void {
2016-11-11 10:47:34 -08:00
if (this.control) this.control.reset(value);
}
hasError(errorCode: string, path: string[] = null): boolean {
2016-11-11 10:47:34 -08:00
return this.control ? this.control.hasError(errorCode, path) : false;
}
getError(errorCode: string, path: string[] = null): any {
2016-11-11 10:47:34 -08:00
return this.control ? this.control.getError(errorCode, path) : null;
}
2016-06-08 15:36:24 -07:00
}