I have created a custom form control (using ControlValueAccessor) for input element, having following code for the writeValue method.
@ViewChild('inputElement', {static: true}) input;
writeValue(obj: any): void {
this.renderer.setAttribute(this.input.nativeElement, 'value', obj);
}
This method updates the view (input element) only once, that is when I initialize the form. If I manually patch the value of the form control associates with the above component, the form control gets updated, but the view doesn't get updated.
But, If I use the setProperty method instead of the setAttribute method, as follows,
@ViewChild('inputElement', {static: true}) input;
writeValue(obj: any): void {
this.renderer.setProperty(this.input.nativeElement, 'value', obj);
}
The view gets updated.
But the problem is, documents says that value is an attribute in HTML, not a dom property.
Can someone explain what is the difference between an attribute and a property in HTML which makes such behaviour in Renderer2 of Angular?