Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send input value to typescript (without button send)

Tags:

html

angular

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.

like image 530
Pluto Avatar asked May 30 '20 17:05

Pluto


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}}
like image 183
mr. pc_coder Avatar answered Nov 15 '22 20:11

mr. pc_coder