I'm looking to use this example provided in the Angular documentation to leverage Dynamic forms in combination with the [(ngmodel)]. so that dynamic form controls can be bound to an model.
However, when I try to bind a control to [(ngMode)], I see the error message
Expression has changed after it was checked. Previous value: 'false'. Current value: 'true'.
Here is an sample Plunker with the changes made.
I modified the QuestionBase class to hold a key
export class QuestionBase<T>{
...
modelKey:string;
...
}
Within the QuestionService, each question now has the name of the model it should update
new TextboxQuestion({
...
modelKey: 'firstName'
}),
In the DynamicFormQuestionComponent the model is passed in as an input varialbe
export class DynamicFormQuestionComponent {
...
@Input() model: SampleModel;
...
}
The DynamicFormQuestionComponent HTML fields have been modified to use [(ngModel)]
<input *ngSwitchCase="'textbox'" [formControlName]="question.key"
[id]="question.key" [type]="question.type" [(ngModel)]="model[question.modelKey]">
Here the control should be bound to the the resolved 'model[question.modelKey]'
Given that I don't see [(ngModel)] used in the example provided in the official documentation.
Any assistance is appreciated.
Thank you kindly.