M
M
microf2018-05-25 13:55:00
Angular
microf, 2018-05-25 13:55:00

How to apply formControlName to input?

Good afternoon. I returned here to Angular and remembered that I hadn’t figured out the ControlValueAccessor in any way. The Custom Component
link generates code like this, where everything is applied directly to the component, not to
<ui-input-field>ng-valid ng-pristininput

<ui-input-field _ngcontent-c8="" formcontrolname="email" _nghost-c9="" ng-reflect-name="email" class="ng-untouched ng-pristine ng-valid">
<input _ngcontent-c9="">
<span _ngcontent-c9="" class="bar"></span>
<label _ngcontent-c9=""></label>
</ui-input-field>

As I understand it, for this reason, the transfer of formcontrolname to the component does not work (or I'm wrong).
How to apply it exactly to the input?
writeValue(value) {
    if (!value || typeof value !== 'string') {
      console.log('not value');
      return;
    }
  }


  onChange: any = () => {
  }
  onTouched: any = () => {
  }

  registerOnChange(fn) {
    this.onChange(fn);
  }
  registerOnTouched(fn) {
    this.onTouched(fn);
  }

Link

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Stroykin, 2018-05-25
@microf

Based on your example - link . Example with ControlValueAccessor and added example with FromGroup (file input-control.component.ts )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question