1. <div (click)="handleClick()">{{title}}</div>
  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'app-root',
  4. templateUrl: './app.component.html',
  5. styleUrls: ['./app.component.css']
  6. })
  7. export class AppComponent {
  8. title = 'my-app';
  9. handleClick():void{
  10. console.log("click")
  11. }
  12. }

事件获取state中的数据

  1. export class AppComponent {
  2. title = 'my-app';
  3. handleClick():void{
  4. console.log(this.title)
  5. }
  6. }

改变数据

  1. export class AppComponent {
  2. title = 'my-app';
  3. handleClick():void{
  4. console.log(this.title)
  5. this.title = "change"
  6. }
  7. }