I'm currently trying to extend the FormGroup type of Angular5 to implement a custom method to receive modelstate errors and display them into another custom component.
Unfortunately, I've been receiving a not so informative error:
Error: ServerValidatedForm/src/platform/svalidated/group.component.ts:30:1: Error encountered in metadata generated for exported symbol 'SVFormGroup':
ServerValidatedForm/src/platform/svalidated/group.component.ts:33:22: Metadata collected contains an error that will be reported at runtime: Expression form not supported.
I'm suspecting that there's something that I miss on TypeScripting itself. Its good to notice that I've already cleaned up node_modules, removed all metadata from project and transpiled again and, every time I hit the same error.
I'm using:
"@angular/animations": "5.0.1",
"@angular/cli": "^1.5.0",
"@angular/common": "5.0.1",
"@angular/compiler": "^5.0.1",
"@angular/compiler-cli": "^5.0.1",
"@angular/core": "5.0.1",
"@angular/forms": "^5.0.1"
The important code is here, and ANY help will be of assitance:
import { Injectable } from "@angular/core";
import { FormGroup } from "@angular/forms";
import { AbstractControlOptions } from "@angular/forms/src/model";
@Injectable()
export class SVFormGroup extends FormGroup {
constructor(
controls: {[key: string]: any},
validatorOrOpts?: ValidatorFn|ValidatorFn[]|AbstractControlOptions|null,
asyncValidator?: AsyncValidatorFn|AsyncValidatorFn[]|null) {
super(controls, validatorOrOpts, asyncValidator);
}
setFromModelState(response: any, form: SVFormGroup) {
if(response.error && response.error.ModelState){
let validationErrorDictionary = response.error.ModelState;
for (var fieldName in validationErrorDictionary) {
if (validationErrorDictionary.hasOwnProperty(fieldName)) {
if (form.controls[fieldName]) {
form.controls[fieldName].setErrors(validationErrorDictionary[fieldName]);
} else {
this.setErrors(Object.assign(this.errors, validationErrorDictionary[fieldName]));
}
}
}
}
} } `
And the complete code can be found at: https://github.com/eduelias/servervalidatedform