How to get FormControl instance from ControlValueAccessor

前端 未结 3 662
温柔的废话
温柔的废话 2020-12-29 05:35

I\'ve the following component:

@Component({
    selector: \'pc-radio-button\',
    templateUrl: \'./radio-button.component.html\',
    providers: [
        {         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-29 06:18

    Goes from my answer of this stackblitz question

    Another solution is add as provider NG_VALIDATORS. So, in our function validate we can store the control in a variable

    public validate(c: FormControl) {
      if (!this.control)
        this.control=c;
      return null;
    

    See stackblitz

提交回复
热议问题