一、回车事件
第一种
<input type="text" #box (keyup.enter)="handleEnter(box.value)">
handleEnter(val:any){
console.log(val)
}
第二种
<input type="text" (keyup)="handleEnter($event)">
handleEnter(event:any){
console.log(event.keyCode)
}
二、点击事件
<p (click)="handleClick()">{{msg}}</p>
//ts
export class HeaderComponent implements OnInit {
...
public msg:string="I like write code"
constructor() { }
ngOnInit() {
}
handleClick(){
this.msg="change"
}
}