create Observable from result

前端 未结 2 1899
滥情空心
滥情空心 2021-02-03 19:48

I am trying Angular2.

I noticed that the http service use Observable object instead of Promise (I don\'t like much that choice.. async

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-03 20:26

    This is my working solution:

    if (this._heroes != null && this._heroes !== undefined) {
        return Observable.create(observer => {
            observer.next(this._heroes);
            observer.complete();
        });
    }
    

    I hope that this is the best solution.

提交回复
热议问题