custom controls - Angular 2 - ControlValueAccessor - How to implement? -




i keep having "no value accessor form control unspecified name attribute"

some ngdefaultcontrol should added not trigger change in component

i tried implement controlvalueaccessor instead error message above

import { component, oninit,input,onchanges,simplechange } '@angular/core'; import { controlvalueaccessor } "@angular/forms";  import { productsservice } '../../pages/products/products.service';  @component({     selector: 'my-product-input',     templateurl: './productinput.component.html',     styleurls: ['./productinput.component.css'], })  export class productinputcomponent implements oninit,onchanges,controlvalueaccessor {      onchange;      @input('productid') productid:number=null;      private product:any;      constructor(         private productsservice: productsservice,         ) {}      ngoninit() {         this.getproduct();     }      getproduct() ...      ngonchanges(changes: { [propname: string]: simplechange }) {         ... never gets triggered     }      writevalue( value : ) : void {         this.productid=value;         this.getproduct();     }      registeronchange( fn : ) : void {         this.onchange = fn;     }      // not sure entry     change( $event ) {         this.onchange($event.target.textcontent);     }      setdisabledstate( _isdisabled : boolean ) : void {     }      registerontouched(_fn: any):void     {      } } 

what doing wrong ? cant find example recent implementation

thanks

you need tell injector controlvalueacessor creating injection token capabilities of ng_value_accessor , adding providers of component :

export const my_value_accessor: = {   provide: ng_value_accessor,   useexisting: forwardref(() => productinputcomponent),   multi: true };  @component({     selector: 'my-product-input',     templateurl: './productinput.component.html',     styleurls: ['./productinput.component.css'],     providers: [my_value_accessor] }) ... 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -