如何显示每行数组的每个值 - IONIC 2

时间:2017-10-28 08:23:14

标签: angular ionic-framework ionic2

我们的代码是home.html

<div *ngFor="let Server of Servers; let i = index; let f=first; let l=last;" >
 <p> {{Servers}}</p>
</div>

home.ts中创建的数组,如下所示

Servers=['1','2','3'];

我希望home.html页面上的结果应该像:

1
2
3
  

请告知。

3 个答案:

答案 0 :(得分:1)

应该是,

<div *ngFor="let Server of Servers; let i = index; let f=first; let l=last;" >
     <p> {{Server}}</p>
 </div>

答案 1 :(得分:0)

您已在{{Servers}}代码中添加{{Server}}而非<p>

<div *ngFor="let Server of Servers; let i = index; let f=first; let l=last;" >
    <!-- Change to this -->
    <p>{{Server}}</p>
    <!-- Change to this -->
</div>

简单的例子是:

<div *ngFor="let item of Servers;" >
    <p>{{item}}</p>
</div>

答案 2 :(得分:0)

最合乎逻辑的解决方案:

<ion-list>
  <ion-item ion-item *ngFor="let Server of Servers; let i = index; let f=first; let l=last;"">
   <p> {{Server}}</p>
  </ion-item> 
</ion-list>

棘手的(不推荐):

<div *ngFor="let Server of Servers; let i = index; let f=first; let l=last;" >
 <p> {{Server}}</p>
<br/>
</div>