我正在使用Ionic2创建一个应用程序,我正在尝试打印一个阵列中的歌曲列表列表。 我有这两个文件,但我无法获得歌曲列表,我甚至没有收到错误和警告。
songlist.ts
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import {Page} from 'ionic-angular';
@Component({
templateUrl: 'build/pages/songlist/songlist.html',
})
export class Songlist {
songs
test
constructor(private navCtrl: NavController) {
this.songs = ['Song 1','song 2','song 3'];
this.test = "this is a test";
}
}
songlist.html
<ion-header>
<ion-navbar>
<ion-title>Ionic 2 Application</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
{{test}} // "this is a test" is correctly printed
<ion-list class="messageList">
<ion-item *ngFor="let item of songs">{{item}}</ion-item>
</ion-list>
</ion-content>
答案 0 :(得分:0)
songs
数组未正确声明:
export class Songlist {
private songs: Array<string>; // <- That's how the array should be declared
constructor(private navCtrl: NavController) {
this.songs = ['Song 1','song 2','song 3'];
}
}