说我有这个功能......
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
});
}
如何将stuff对象返回给观察者而不是Piece类型的“数据”?
答案 0 :(得分:2)
如果您使用代码块,则需要明确的return
:
public getStuff(): Observable<Stuff> {
return.http.get('url')
.map(res => res.json())
.map((data: Piece) => {
var stuff = new Stuff();
return stuff;
});
}