2016-06-23 09:47:54 -07:00
|
|
|
/**
|
|
|
|
|
* @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
|
|
|
|
|
*/
|
|
|
|
|
|
2017-03-01 10:28:52 -08:00
|
|
|
import {Observable} from 'rxjs/Observable';
|
2016-06-08 16:38:52 -07:00
|
|
|
import {AbstractControl} from '../model';
|
2017-02-23 20:53:29 +03:00
|
|
|
import {ValidationErrors} from './validators';
|
2016-06-08 16:38:52 -07:00
|
|
|
|
2016-06-08 15:36:24 -07:00
|
|
|
/**
|
|
|
|
|
* Base class for control directives.
|
|
|
|
|
*
|
|
|
|
|
* Only used internally in the forms module.
|
|
|
|
|
*
|
2016-08-17 07:44:39 -07:00
|
|
|
* @stable
|
2016-06-08 15:36:24 -07:00
|
|
|
*/
|
|
|
|
|
export abstract class AbstractControlDirective {
|
2017-04-17 11:13:30 -07:00
|
|
|
abstract get control(): AbstractControl|null;
|
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
|
|
|
|
2017-04-17 11:13:30 -07:00
|
|
|
get valid(): boolean|null { return this.control ? this.control.valid : null; }
|
2016-06-08 15:36:24 -07:00
|
|
|
|
2017-04-17 11:13:30 -07:00
|
|
|
get invalid(): boolean|null { return this.control ? this.control.invalid : null; }
|
2016-08-01 18:41:25 -07:00
|
|
|
|
2017-04-17 11:13:30 -07:00
|
|
|
get pending(): boolean|null { return this.control ? this.control.pending : null; }
|
2016-08-01 18:41:25 -07:00
|
|
|
|
2017-02-23 20:53:29 +03:00
|
|
|
get errors(): ValidationErrors|null { return this.control ? this.control.errors : null; }
|
2016-06-08 15:36:24 -07:00
|
|
|
|
2017-04-17 11:13:30 -07:00
|
|
|
get pristine(): boolean|null { return this.control ? this.control.pristine : null; }
|
2016-06-08 15:36:24 -07:00
|
|
|
|
2017-04-17 11:13:30 -07:00
|
|
|
get dirty(): boolean|null { return this.control ? this.control.dirty : null; }
|
2016-06-08 15:36:24 -07:00
|
|
|
|
2017-04-17 11:13:30 -07:00
|
|
|
get touched(): boolean|null { return this.control ? this.control.touched : null; }
|
2016-06-08 15:36:24 -07:00
|
|
|
|
2017-08-05 09:59:32 +12:00
|
|
|
get status(): string|null { return this.control ? this.control.status : null; }
|
|
|
|
|
|
2017-04-17 11:13:30 -07:00
|
|
|
get untouched(): boolean|null { return this.control ? this.control.untouched : null; }
|
2016-06-08 15:36:24 -07:00
|
|
|
|
2017-04-17 11:13:30 -07:00
|
|
|
get disabled(): boolean|null { return this.control ? this.control.disabled : null; }
|
2016-08-24 16:58:43 -07:00
|
|
|
|
2017-04-17 11:13:30 -07:00
|
|
|
get enabled(): boolean|null { return this.control ? this.control.enabled : null; }
|
2016-08-24 16:58:43 -07:00
|
|
|
|
2017-04-17 11:13:30 -07:00
|
|
|
get statusChanges(): Observable<any>|null {
|
|
|
|
|
return this.control ? this.control.statusChanges : null;
|
|
|
|
|
}
|
2016-06-24 13:37:42 -07:00
|
|
|
|
2017-04-17 11:13:30 -07:00
|
|
|
get valueChanges(): Observable<any>|null {
|
|
|
|
|
return this.control ? this.control.valueChanges : null;
|
|
|
|
|
}
|
2016-06-24 13:37:42 -07:00
|
|
|
|
2017-04-17 11:13:30 -07:00
|
|
|
get path(): string[]|null { return null; }
|
2016-07-12 15:02:25 -07:00
|
|
|
|
|
|
|
|
reset(value: any = undefined): void {
|
2016-11-11 10:47:34 -08:00
|
|
|
if (this.control) this.control.reset(value);
|
2016-07-12 15:02:25 -07:00
|
|
|
}
|
2016-10-19 18:49:02 +02:00
|
|
|
|
2017-04-17 11:13:30 -07:00
|
|
|
hasError(errorCode: string, path?: string[]): boolean {
|
2016-11-11 10:47:34 -08:00
|
|
|
return this.control ? this.control.hasError(errorCode, path) : false;
|
2016-10-19 18:49:02 +02:00
|
|
|
}
|
|
|
|
|
|
2017-04-17 11:13:30 -07:00
|
|
|
getError(errorCode: string, path?: string[]): any {
|
2016-11-11 10:47:34 -08:00
|
|
|
return this.control ? this.control.getError(errorCode, path) : null;
|
2016-10-19 18:49:02 +02:00
|
|
|
}
|
2016-06-08 15:36:24 -07:00
|
|
|
}
|