Angular 2 - formControlName inside component

后端 未结 7 1524
闹比i
闹比i 2020-11-30 00:21

I want to create a custom input component that I can use with the FormBuilder API. How do I add formControlName inside a component?

Template:

7条回答
  •  天命终不由人
    2020-11-30 01:13

    The main idea here is that you have to link the FormControl to the FormGroup, this can be done be passing the FormGroup to each input component...

    So your input template might look something like the following:

    {{ message }}

    Where the @Input's for the input component will be form, label, inputName and message.

    It would be used like this:

    For more info on custom Form Input Components I would recomend taking a look through Angular's Dynamic Forms. Also if you want more information on how to get the @Input and @Output working take a look through the Angular Docs Here

提交回复
热议问题