angular 实现文本框输入字符串 实时显示

html :

  <p>Current item name: {{currentItem.name}}</p>
  <p>
    <label for="without">without NgModel:</label>
    <input [value]="currentItem.name" (input)="currentItem.name=getValue($event)" id="without">
  </p>

注:(input)="currentItem.name=getValue($event)"  此input调用getValue($event)方法实现实时显示输入内容

ts:

getValue(event: Event): string {
    return (event.target as HTMLInputElement).value;
  }
 
原文地址:https://www.cnblogs.com/fuyao/p/15329917.html