How to generate forms dynamically by angular4

how do I generate different forms based on the data passed in the background? Such as user registration and user login, dynamic generation of form components?

Mar.14,2021

globally define a FormGroup ,
and then dynamically add FormControl to FormGroup based on different data.

public formGroup: FormGroup;

this.xxxService.getData().subscribe((data: Array<string>) => {
    this.formGroup = new FormGroup({});
    data.forEach((key: string) => {
        this.formGroup.addControl(key, new FormControl(''));
    });
});

to see the response form


you can use form-create to dynamically create form forms based on parameters, supporting check box, radio box, input box, drop-down selection box and other elements, as well as, provinces and cities three-level linkage, time selection, date selection, color selection, file / picture upload function. github address

Menu