无法使用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'];
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章