This plunker work in Firefox with out any console error, but in Chrome I get message:
Error in formcontrol
<ul>
<li *ngFor="let item of data">
<label>
<input type="radio" name="radio1"
[value]="item.id"
[formControl]="childControl"
(input)="fn($event.target.value)" >
<p>{{ item.title }}</p>
</label>
</li>
</ul>
Cannot find control with unspecified name attribute
Since you have [formControl]="childControl"
specified in your MyChild template you need a FormControl specified in your MyChild class.
export class MyChild implements ControlValueAccessor {
@Input() data: any;
out: any;
childControl = new FormControl();
fn: (value:any) => void;
validateFn: any = () => {};
constructor(private _renderer: Renderer, private _elementRef: ElementRef) {}
writeValue(value: any): void {
this._renderer.setElementProperty(this._elementRef, 'checked', value == this._elementRef.nativeElement.value);
}
registerOnChange(fn: (value: any) => void) {
this.onChange = fn;
}
registerOnTouched() {}
}
However after that you end up with an error that seems to be unrelated TypeError: v is not a function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With