一、回车事件

第一种

  1. <input type="text" #box (keyup.enter)="handleEnter(box.value)">
  1. handleEnter(val:any){
  2. console.log(val)
  3. }

第二种

  1. <input type="text" (keyup)="handleEnter($event)">
  1. handleEnter(event:any){
  2. console.log(event.keyCode)
  3. }

二、点击事件

  1. <p (click)="handleClick()">{{msg}}</p>
  2. //ts
  3. export class HeaderComponent implements OnInit {
  4. ...
  5. public msg:string="I like write code"
  6. constructor() { }
  7. ngOnInit() {
  8. }
  9. handleClick(){
  10. this.msg="change"
  11. }
  12. }