Pls help me! Array not showing in my list :(


#1

I have a question, i hope someone could help me out :slight_smile:

I try to read a m3u file with xhr. That all works perfect, but when i try to set the reponse to an array to show it in my list (ngFor) - my list is empty :frowning:

@IonicPage()
@Component({
  selector: 'page-radiotv',
  templateUrl: 'radiotv.html',
})
export class RadiotvPage {

  public tvlist: any[];

  constructor(public navCtrl: NavController, public navParams: NavParams) {}
  
  ionViewDidLoad() {
    console.log('ionViewDidLoad RadiotvPage');

    var xhr = new XMLHttpRequest();
    xhr.open("GET", "assets/m3u/TV.m3u");
    xhr.overrideMimeType("audio/x-mpegurl"); // Needed, see below.
    xhr.onload = parse;
    xhr.send();

    // Parse it
    function parse () {
      this.tvlist = M3U.parse(this.response);

      console.log(this.tvlist);

    };
  }
}
  <ion-list>
    <ion-item *ngFor="let tvsender of tvlist | async">
      {{tvsender.title}}
    </ion-item>
  </ion-list>

#2

i found the solution, if somebody needs it :slight_smile:

import { Component, ChangeDetectorRef } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';

/**
 * Generated class for the RadiotvPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-radiotv',
  templateUrl: 'radiotv.html',
})
export class RadiotvPage {

  public tvlist = [];

  constructor(public navCtrl: NavController, public navParams: NavParams, public http: Http, private cd: ChangeDetectorRef) {
    this.http.get('assets/m3u/TV.m3u').subscribe(data => {

        this.tvlist = M3U.parse(data['_body']);

        console.log(this.tvlist);
    });
  }
}