fix(forms): match getError and hasError to get method signature (#20211)

Internally getError and hasError call the AbstractControl#get method which takes  `path: Array<string | number> | string` as input, since there are different ways to traverse the AbstractControl tree.
This change matches the method signitures of all methods that use this.

PR Close #20211
This commit is contained in:
Fabian Wiles
2018-12-22 13:39:37 +13:00
committed by Ben Lesh
parent e268a0579a
commit 1b0b36d143
4 changed files with 74 additions and 8 deletions

View File

@ -177,7 +177,7 @@ export abstract class AbstractControlDirective {
*
* If the control is not present, false is returned.
*/
hasError(errorCode: string, path?: string[]): boolean {
hasError(errorCode: string, path?: Array<string|number>|string): boolean {
return this.control ? this.control.hasError(errorCode, path) : false;
}
@ -208,7 +208,7 @@ export abstract class AbstractControlDirective {
* @returns error data for that particular error. If the control or error is not present,
* null is returned.
*/
getError(errorCode: string, path?: string[]): any {
getError(errorCode: string, path?: Array<string|number>|string): any {
return this.control ? this.control.getError(errorCode, path) : null;
}
}

View File

@ -671,7 +671,7 @@ export abstract class AbstractControl {
* @returns error data for that particular error. If the control or error is not present,
* null is returned.
*/
getError(errorCode: string, path?: string[]): any {
getError(errorCode: string, path?: Array<string|number>|string): any {
const control = path ? this.get(path) : this;
return control && control.errors ? control.errors[errorCode] : null;
}
@ -706,7 +706,9 @@ export abstract class AbstractControl {
*
* If the control is not present, false is returned.
*/
hasError(errorCode: string, path?: string[]): boolean { return !!this.getError(errorCode, path); }
hasError(errorCode: string, path?: Array<string|number>|string): boolean {
return !!this.getError(errorCode, path);
}
/**
* Retrieves the top-level ancestor of this control.