添加组件

  1. ng generate component heroes

双向数据绑定

app.modules.ts

  1. import { FormsModule } from '@angular/forms';
  1. <input [(ngModel)]="hero.name" placeholder="name">

循环

  1. <li *ngFor="let hero of heroes">
  2. <span class="badge">{{hero.id}}</span> {{hero.name}}
  3. </li>

事件

  1. <ul class="heroes">
  2. <li *ngFor="let hero of heroes" (click)="onSelect(hero)">
  3. <span class="badge">{{hero.id}}</span> {{hero.name}}
  4. </li>
  5. </ul>
文档更新时间: 2019-04-04 12:05