0

Here i have requirement like if i type type anything in Textbox it should be Reflect back to Component

<label> Search FRom Table:</label> <input (change)="someval()">

Someval(){
//Here i need that TextBox value
}

1 Answers1

0

You can achieve this in Two way data binding method and so on.

Html Looks like following

    <label> Search From Table:</label>
    <input name="searchTxt" [(ngModel)]="searchTxt" (input)="someval()">

    {{searchTxt}} <!-- here iam printed html file also -->

Typescript File:

//Add one variable 
public searchTxt:any;

someval(){
 console.log("Here iam printed variable",this.searchTxt);
}

Make sure you have to import Forms Module in app module file other wise it show error like this enter image description here

app.module.ts

import { FormsModule } from '@angular/forms'

imports: [
    FormsModule,
],

For more details about related here, please visit:

https://www.code-sample.com/2017/05/angular2-input-textbox-change-events.html

Angular 2 change event on every keypress

Pang
  • 9,564
  • 146
  • 81
  • 122
Karnan Muthukumar
  • 1,843
  • 1
  • 8
  • 15