Send input value to typescript (without button send)

Viewed 896

I have a regular input text:

<form>
    <input type="text" oninput="sendInput()" />
</form>

I want to send what the user typed in the box into the typescript file (without a submit button or something) when the user has finished typing, send the input to the typescript.

I try with this code but it's not working.

1 Answers

Demo use ngModel two way binding

<input type="text" [(ngModel)]="inputParam"/>    
<p>{{inputParam}}</p>

Demo or use ViewChild as a way

component.ts

inputParam=""
  @ViewChild('input') _input: ElementRef;
  sendInput(){
    this.inputParam= this._input.nativeElement.value;
  }

html part

<form >
    <input #input type="text" (input)="sendInput()"/>
</form>
{{inputParam}}
Related