user3689167
user3689167

Reputation: 873

Angular2 - return observable of object created in map function

Say I have this function...

public getStuff(): Observable<Stuff> {
     return.http.get('url')
          .map(res => res.json())
          .map((data: Piece) => {
               var stuff = new Stuff();
               // Apply logic to "data", modify stuff model, return stuff to subscriber
          });
}

How do I return the stuff object to the observer instead of the "data" of type Piece?

Upvotes: 1

Views: 3640

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657476

If you use a code block you need an explicit return:

public getStuff(): Observable<Stuff> {
     return.http.get('url')
          .map(res => res.json())
          .map((data: Piece) => {
               var stuff = new Stuff();
               return stuff;
          });
}

Upvotes: 3

Related Questions