3-1(click)—点击更改

  1. //header.component.html
  2. <p (click)="handleClick()">{{msg}}</p>
  1. //header.component.ts
  2. export class HeaderComponent implements OnInit {
  3. public msg:string="我喜欢"
  4. constructor() { }
  5. ngOnInit() {
  6. }
  7. handleClick(){
  8. this.msg="change"
  9. }
  10. }

3-2(keyup)—获取input键盘码

  1. //header.component.html
  2. <input type="text" (keyup)="handleEnter($event)">
  1. //header.component.ts
  2. export class HeaderComponent implements OnInit {
  3. ...
  4. handleEnter(event:any){
  5. console.log(event.keyCode) //键盘码
  6. }
  7. }

3-3(key.enter)—获取input输入框中的值

  1. //header.component.html
  2. <input #box (keyup.enter)="handleEnter(box.value)">
  1. //header.component.ts
  2. handleEnter(value:string){
  3. console.log(value)
  4. }