• 数据绑定就是将组件类中的数据显示在组件模板中,当组件类中的数据发生变化时会自动被同步到组件模板中(数据驱动 DOM )
    • 在 Angular 中使用差值表达式进行数据绑定,即 {{ }} 大胡子语法 ```typescript // src/app/app.component.html

      {{ message }}

      {{ getInfo() }}

      {{ a == b ? ‘相等’ : ‘不等’ }}

      {{ ‘Hello Angular’ }}

    1. ```typescript
    2. // src/app/app.component.ts
    3. export class AppComponent {
    4. message: string = 'angular-test';
    5. htmlSnippet: string = '<h1>htmlString</h1>'
    6. a: number = 1
    7. b: number = 1
    8. getInfo() {
    9. return '我是 getInfo 方法中返回的数据'
    10. }
    11. }
    • 页面显示

    image.png