I'm trying to use Formly in Angular 9 for some dynamicly configured forms.
It was worked well with angular 8, but when I upgrade the project to angular 9, i had the following errors.
My component class:
export class CityFormComponent implements OnInit {
editingCity?: City;
loading: boolean;
form = new FormGroup({});
model = {};
fields: FormlyFieldConfig[];
constructor(
private store: Store<fromApp.AppState>,
public dialogRef: MatDialogRef<CityFormComponent>,
@Inject(MAT_DIALOG_DATA) public data: { id?: number, modelForm: any, }) { }
ngOnInit() {
if (this.data.modelForm) {
this.fields = this.data.modelForm.fields;
// console.log(this.fields);
}
if (this.data.id) {
this.store.dispatch(new CityEditing(this.data.id));
} else {
this.store.dispatch(new CityCreating());
}
this.store.select('cities').subscribe(state => {
this.loading = state.loading;
if (state.selectedCityId > 0) {
this.editingCity = state.cities.find(loc => loc.id === state.selectedCityId);
} else {
this.editingCity = {};
}
});
}
//...
}
<form [formGroup]="form" (ngSubmit)="submit()">
<formly-form [form]="form" [model]="editingCity" [fields]="fields"></formly-form>
<button type="submit" [disabled]="!form.valid" mat-raised-button color="primary">Save</button>
</form>
Here u can see, I have my fields: FormlyFieldConfig[]
from MAT_DIALOG_DATA (I get this form config from backend), and it looks like normal FormlyFieldConfig[]:
fields: [
0: {
className: ""
defaultValue: null
key: "name"
templateOptions: {label: "Название", placeholder: "", description: "", required: true, options: []}
description: ""
label: "Название"
options: []
placeholder: ""
required: true
type: "input"
validation: {messages: []}
messages: [],
},
]
At the same time, if i hardcode fields property by adding
this.fields = [
{
key: 'firstname',
type: 'input',
},
];
at the end of ngOnInit(), it'll work fine.
Have anybody any ideas how to fix it?