简体   繁体   English

Http.get()。catch的返回类型是什么?

[英]What is the return type of Http.get().catch?

I'm currently learning angular 2, taking Deborah Kurata's Pluralsight class (Angular 2: Getting Started). 我目前正在学习Deborah Kurata的Pluralsight课程(Angular 2:入门),学习Angular 2。 It's great so far, but, for the life of me, I can't seem to discover what the return type of my .catch should be. 到目前为止非常好,但是,对于我的一生来说,我似乎无法发现.catch的返回类型应该是什么。 In her course, and in every example I've found so far, the return type is left blank. 在她的课程中,以及到目前为止我发现的每个示例中,返回类型都为空。

This is what I have: 这就是我所拥有的:

getProducts(): Observable<IProduct[]> {
    return this._http.get("someurl")
        .map {.....}
        .catch(this.handleError);
}

handleError (response: Response) **/*what goes here?*/** {
    // the code in the course says Observable.throw, but chrome is
    // complaining that there is no such function. I have tracked 
    // down "static throw: typeof ErrorObservable.create;" in 
    // Observable.ts but I'm not sure what's going on here.
}

The most common return type is an Observable . 最常见的返回类型是Observable

To be precise, the selector function to the catch() operator is defined as: 确切地说, catch()运算符的选择器函数定义为:

(err: any, caught: Observable): ObservableInput

The returned Observable is subscribed using the subscribeToResult which supports multiple return types (that's why there's ObservableInput and not just Observable ). 使用支持多种返回类型的subscribeToResult返回的Observable(这就是为什么有ObservableInput而不是Observable )。 Anyway, it's easier to have a look at the examples in the source code that aren't in the online documentation yet where you should be able to understand how it works: https://github.com/ReactiveX/rxjs/blob/master/src/operator/catch.ts#L8 无论如何,在源代码中没有在线文档的示例中查找示例会更容易,您应该可以在其中了解其工作方式: https : //github.com/ReactiveX/rxjs/blob/master /src/operator/catch.ts#L8

Or see what subscribeToResult supports: https://github.com/ReactiveX/rxjs/blob/master/src/util/subscribeToResult.ts#L17 或查看subscribeToResult支持的内容: https : //github.com/ReactiveX/rxjs/blob/master/src/util/subscribeToResult.ts#L17

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM