1. js --onclick
  2. jquery--click
  3. vue--@click
  4. React--onClick
  5. Angular--(click)
  1. # app.component.ts
  2. import { Component } from '@angular/core';
  3. @Component({
  4. //根主键
  5. selector: 'app-root',
  6. templateUrl: './app.component.html',
  7. styleUrls: ['./app.component.css']
  8. })
  9. export class AppComponent {
  10. title = 'my-app';
  11. handleClick():void{
  12. console.log("click");
  13. }
  14. }
  15. # app.component.html
  16. <div (click)="handleClick()">{{title}}</div>

2-1. 通过事件获取this.title中的数据

  1. # app.component.ts
  2. )
  3. export class AppComponent {
  4. title = 'my-app';
  5. handleClick():void{
  6. console.log(this.title);
  7. }
  8. }
  9. # app.component.html
  10. <div (click)="handleClick()">{{title}}</div>

2-2. 通过事件改变this.title中的数据

  1. # app.component.ts
  2. export class AppComponent {
  3. title = 'my-app';
  4. handleClick():void{
  5. this.title = 'wang'
  6. }
  7. }
  8. # app.component.html
  9. <div (click)="handleClick()">{{title}}</div>