I keep having "No value accessor for form control with unspecified name attribute"
some say ngDefaultControl should be added but it does not trigger any change in my component
I tried to implement ControlValueAccessor instead but I get back to the error message above
import { Component, OnInit,Input,OnChanges,SimpleChange } from '@angular/core';
import { ControlValueAccessor } from "@angular/forms";
import { ProductsService } from '../../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 : any ) : void {
this.productID=value;
this.getProduct();
}
registerOnChange( fn : any ) : void {
this.onChange = fn;
}
// not sure about this entry
change( $event ) {
this.onChange($event.target.textContent);
}
setDisabledState( _isDisabled : boolean ) : void {
}
registerOnTouched(_fn: any):void
{
}
}
What am I doing wrong ? I cant find any example for recent implementation
thanks