3-1(click)—点击更改
//header.component.html
<p (click)="handleClick()">{{msg}}</p>
//header.component.ts
export class HeaderComponent implements OnInit {
public msg:string="我喜欢"
constructor() { }
ngOnInit() {
}
handleClick(){
this.msg="change"
}
}
3-2(keyup)—获取input键盘码
//header.component.html
<input type="text" (keyup)="handleEnter($event)">
//header.component.ts
export class HeaderComponent implements OnInit {
...
handleEnter(event:any){
console.log(event.keyCode) //键盘码
}
}
3-3(key.enter)—获取input输入框中的值
//header.component.html
<input #box (keyup.enter)="handleEnter(box.value)">
//header.component.ts
handleEnter(value:string){
console.log(value)
}