How can I create my own component for FormControls?

后端 未结 2 1890
后悔当初
后悔当初 2021-01-03 15:25

I would like to create a form and use a new, custom component for its controls. So I created a new component and included it into the parent form. But although the parent fo

2条回答
  •  一整个雨季
    2021-01-03 15:40

    You should also be passing the formGroup instance along with control name to your custom component. And then create a form control under that formGroup in custom component. Your custom component will create the control virtually under the same formGroup that you have provided.

    custom.component.ts

    import { Component, Input, OnInit }       from '@angular/core';
    
    @Component({
      selector: 'ava-form-control',
      template: `  
提交回复
热议问题