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:
Angular 8 and 9: Use viewProvider in you custom component. Working example:
@Component({
selector: 'app-input',
templateUrl: './input.component.html',
styleUrls: ['./input.component.scss'],
viewProviders: [
{
provide: ControlContainer,
useExisting: FormGroupDirective
}
]
})
Now, when you assign formControlName, your component will attach itself to the parent form.
or