CodyBugstein
CodyBugstein

Reputation: 23322

How do you call onNext from inside a nested Observable

I'm working in Angular2 with Typescript.

I created a function that creates and returns an Observable. Inside this Observable, another observable is subscribed and I want to call onNext when the inner observable receives an event. Here is the code

getImages(hashtag: string) {

    var imagesurl = this.flickrAPI.fetchImagesByTag + hashtag;
    return Observable.create((o) => {
        this.httpService.get(imagesurl)
        .map(res => {
            console.log("res");
            console.log(res.json());
            return res.json();
        })
        .map(res => res.photos.photo[0])
        .subscribe((result) => {
            console.log(result);
            console.log(this.generateImageUrl(result));
            o.next(this.generateImageUrl(result));
        });
    });
}

The problem is that I am getting an error that o is not recognized. Apparently from its position inside the subscribe callback, it has become detached from the parameter o that was passed in.

How can I fix this?

Upvotes: 1

Views: 551

Answers (1)

kit
kit

Reputation: 4920

Rx.Observerable has next() method not onNext().

Upvotes: 4

Related Questions