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:
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
|
Reference in New Issue
Block a user