Promise() returning "Undefined"

Hi guys :slight_smile:

Working on my first project in Ionic more or less following this tutorial.
In general trying to call the REST Api, with prayer types , and present it on the screen.

The issue is that, when calling loadPrayerType() from the constrcutor (or on click the button), method prayerProvider.load() return “undevined” value. While inside itselfs it has data (retrieve from API, log, etc). Cheked it on DebugTool on Chrome.

Any suggestion?

BTW I’m newbie on Ionic and JavaSript in general - what probably is a reason :-).

File wspolnota.ts

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import {PrayerProvider} from '../../providers/prayer/prayer';
import { HttpModule } from '@angular/http';

  selector: 'page-wsp-lnota',
  templateUrl: 'wsp-lnota.html',
  providers: [PrayerProvider]

export class WspLnotaPage {
  public prayer_type: any;

  constructor(public navCtrl: NavController, public prayerProvider: PrayerProvider) {
    this.prayerProvider.load().then(data => {
      this.prayer_type = data.results;

File prayer.ts

import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';

export class PrayerProvider {
  data: any;
  constructor(public http: Http) {
    console.log('Hello PrayerProvider Provider'); = null;
  load() {
    if ( {
      console.log("Mam już dane "+;
      // already loaded data
      return Promise.resolve(;
   // don't have the data yet
    return new Promise(resolve => {
        .map(res => res.json())
        .subscribe( data => {
 = data;

I think the code quality in that blog post is abysmal and you should just nuke it from orbit and start over with other sources. I would recommend part 6 of the Tour of Heroes; others might have other suggestions.

Thanks for your advice. Based on it I started worling with this new tutorial …rewrote lots of and stuck in similar place with similar error :-). But keep fighting and found a bag in converting http.get response into Ionic obiects.

A first glance I found your respons as go fly a kite… but decided to follow it… and finally that found solution. Thanks