2016-09-11 36 views
0

Ionic2を使用してアプリケーションを作成していますが、配列から曲のタイトルのリストを印刷しようとしています。 私はこれらの2つのファイルを持っていますが、私は曲のリストを取得できません、私はエラーと警告を取得しません。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> 
+1

を取得してください'あなたがruのときのテキストnアプリ? – micronyks

+0

はい、私はイオン2を見ることができますアプリケーションテキスト – splunk

答えて

0

songs配列が適切に宣言されていない:あなたも `イオン2アプリケーションを

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']; 
    } 
} 
+0

それでも動作しません – splunk

+1

この解決策は動作するはずです。 google Chromeのコンソールでイオンリストの要素を調べると、次のテキストが表示されます:<! - template bindings = { "ng-reflect-ng-for-of": – micronyks

+0

'songs:Array ; test:string;' – micronyks

関連する問題