Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49107

[ts] Property 'subscribe' does not exist on type '(res: any) => any'

$
0
0

@newtonmunene wrote:

Hi guys,

I’m working on a http provider. The issue is with the subscribe module after mapping the json response.
Here is the code for the provider and a screenshot:

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


/*
  Generated class for the PostsProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class PostsProvider {
  data: any = null;

  constructor(public http: HttpClient) {
    console.log('Hello PostsProvider Provider');
    // this.load();
  }

  load() {
    if (this.data) {
      // already loaded data
      return Promise.resolve(this.data);
    }

    // don't have the data yet
    return new Promise(resolve => {
      // We're using Angular HTTP provider to request the data,
      // then on the response, it'll map the JSON data to a parsed JS object.
      // Next, we process the data and resolve the promise with the new data.
      this.http.get('https://randomuser.me/api/?results=10')
        .map((res => res.json())
        .subscribe(data => {
          // we've got back the raw data, now generate the core schedule data
          // and save the data for later reference
          this.data = data.results;
          resolve(this.data);
        }));
    });
  }

}

I’m new to ionic and still learning. I’ve been following tutorials but now i seem to be stuck. Ive tried looking at posts from this and other forums but none have worked for me. Anyone please help. I’m sure its just a small error but it’s huge when you’re learning.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49107

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>