1 动态数据

  1. 语法: this.xxx //设置数据也用

A.app.component.ts
直接定义title = ‘my-app’;

  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. }

2 获取数据

  1. 使用插值表达式 {{ }}

B.app.component.html
里直接使用

  1. <div>{{title}}</div>