Angular4_清空input输入框



Method 1.

Using `ngModel`.

@Component({
  selector: 'my-app',
  template: `
    
`, }) export class App { searchValue:string = ''; clearSearch() { this.searchValue = null; } }

Plunker code: Plunker1

Method 2.

Using null value instead of empty quotation marks.

@Component({
  selector: 'my-app',
  template: `
    
`, }) export class App { searchValue:string = ''; clearSearch() { this.searchValue = null; } }

Plunker code: Plunker2

Method 1.

Using `ngModel`.

@Component({
  selector: 'my-app',
  template: `
    
`, }) export class App { searchValue:string = ''; clearSearch() { this.searchValue = null; } }

Plunker code: Plunker1

Method 2.

Using null value instead of empty quotation marks.

@Component({
  selector: 'my-app',
  template: `
    
`, }) export class App { searchValue:string = ''; clearSearch() { this.searchValue = null; } }

Plunker code: Plunker2

你可能感兴趣的:(Angular2.x)