[英]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'];
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.