1 动态数据

  1. 使用插值表达式 {{ }}
  1. //app.component.ts
  2. import { Component } from '@angular/core';
  3. @Component({
  4. selector: 'app-root',
  5. templateUrl: './app.component.html',
  6. styleUrls: ['./app.component.css']
  7. })
  8. export class AppComponent {
  9. title = 'my-app';
  10. }
  1. // app.component.html
  2. <div>{{title}}</div>

2 获取数据

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