app.component.html

创建一个事件(click)=”handleclick()”
注释:事件名后一定要带()
列表循环*ngFor

  1. <div (click)="handleclick()">{{title}}</div>
  2. //实现列表循环
  3. <div *ngFor="let item of lists">
  4. {{item}}
  5. </div>

app.component.ts

  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. lists:Array<number>=[1,2,3];
  10. handleclick():void{
  11. //可直接指向title
  12. console.log(this.title)
  13. //改变title里面的值
  14. this.title="change"
  15. }
  16. }