首页 > 其他 > 详细

angular 中数据循环 *ngFor

时间:2019-05-17 18:11:12      阅读:335      评论:0      收藏:0      [点我收藏+]
<!--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‘
    }
  ];
}

效果:

技术分享图片

angular 中数据循环 *ngFor

原文:https://www.cnblogs.com/loaderman/p/10882866.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!