Reputation: 163
Hi I am trying to set value to a angular input box but when i do
let input = document.getElementById('mat-input-0');
input.value = "Something"
input box value changes on website but angular does not see any value when I try hit button and set form
Upvotes: 0
Views: 14828
Reputation: 1600
You can bind to the input value property:
<input [value]="value">
or get the element in your TS file using @ViewChild
:
html:
TS:
@ViewChild('input', { static: false }) input: ElementRef;
AfterViewInit() {
// Change the value here
}
Upvotes: 1