简体   繁体   English

无法使用ionic2从数组中检索数据

[英]Can't retrieve data from array with ionic2

I'm creating an app using Ionic2 and I'm trying to print a list of songs titles from an array. 我正在使用Ionic2创建应用程序,并且试图从数组中打印歌​​曲标题列表。 I have these 2 files, but I can't get the list of songs, I don't even get errors and warnings. 我有这两个文件,但我无法获取歌曲列表,甚至都不会收到错误和警告。

songlist.ts 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 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>

The songs array is not properly declared: 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM