angular - How to get FormControl instance from ControlValueAccessor -


i've following component:

@component({     selector: 'pc-radio-button',     templateurl: './radio-button.component.html',     providers: [         {provide: ng_value_accessor, useexisting: forwardref(() => fieldradiobuttoncomponent), multi: true}     ] }) export class radiobuttoncomponent implements controlvalueaccessor {     ... } 

i can assign , alter value through these inputs:

<pc-radio-button [formcontrol]="formcontrol"></pc-radio-button> <pc-radio-button [formcontrolname]="inputcontrolname"></pc-radio-button> 

however need component have direct access assigned formcontrol, need add styles depending on status.

by creating @input() formcontrol not solve problem. not cover case when form control assigned via formcontrolname.

one possible solution ngcontrol instance via injector:

import { ngcontrol } '@angular/forms'; export class passwordcomponent implements controlvalueaccessor {   ...   ngcontrol: ngcontrol;    constructor(private inj: injector) {     ...   }    ngoninit() {     this.ngcontrol = this.inj.get(ngcontrol)   } 

then can status like

ngcontrol.control.status 

see


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -