Angular4_清空input输入框

前端之家收集整理的这篇文章主要介绍了Angular4_清空input输入框前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


Method 1.

Using `ngModel`.

@Component({
  selector: 'my-app',template: `
    <div>
      <input type="text" placeholder="Search..."  [(ngModel)]="searchValue">
      <button (click)="clearSearch()">Clear</button>
    </div>
  `,})
export class App {
  searchValue:string = '';
  clearSearch() {
    this.searchValue = null;
  }
}

Plunker code:Plunker1

Method 2.

Using null value instead of empty quotation marks.

 
      

Plunker code:Plunker2

Method 1.

Using `ngModel`.

 
       

Plunker code:Plunker1

Method 2.

Using null value instead of empty quotation marks.

 
       

Plunker code:Plunker2

原文链接:https://www.f2er.com/angularjs/145581.html

猜你在找的Angularjs相关文章