Angular 4 ng-repeat implementation

2020-03-29 07:30发布

问题:

I'm trying to implement a very basic ng-repeat directive for a Ionic 3 project using Angular 4. I simply don't understand why this code is not returnig anything. I guess the numerous of the Ionic and Angular documentation are confusing me.... Any idea?

home.ts

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

public item = {} ;
public itemsList = [
    {"name":"Mark", "position":"CEO"},
    {"name":"David", "position":"Developer"}
];

  constructor(public navCtrl: NavController) {

  }

}

home.html

<ion-content padding>
    <ion-list>
      <ion-item ng-repeat="item of itemsList">
        <h3> name: {{item.name}}</h3>
        <p> position: {{item.position}}</p>
      </ion-item>
    </ion-list>
</ion-content>

回答1:

<ion-content padding>
    <ion-list>
      <ion-item *ngFor="let item of itemsList">
        <h3> name: {{item.name}}</h3>
        <h3> name: {{item.position}}</h3>
      </ion-item>
    </ion-list>
</ion-content>

Working code is https://gitlab.com/ugur.ayan/temp-ionic/