angular 中數據循環 *ngFor


<!--The content below is only a placeholder and can be replaced.-->
<div style="text-align:center">


  <h1>
    Welcome to {{ title }}
  </h1>

  <h1>循環數據 顯示數據的索引(key)</h1>


  <ul>

    <li *ngFor="let item of list;let key=index;">
      {{key}}---{{item.title}}
    </li>
  </ul>
</div>

<router-outlet></router-outlet>
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  title = 'Angulardemo';
  public list:any[]=[
    {
      "title":'我是數據1'
    },
    {
      "title":'我是數據2'
    },
    {
      "title":'我是數據3'
    }
  ];
}

效果:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM