无法使用ionic2从数组中检索数据
Can't retrieve data from array with ionic2
我正在使用 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>
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'];
}
}
我正在使用 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>
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'];
}
}