Petr M
Petr M

Reputation: 163

How to set value to angular input

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

Answers (1)

Eliran Eliassy
Eliran Eliassy

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

Related Questions