相关疑难解决方法(0)

Angular 2的Http服务不暴露map()和其他RxJS函数

有人知道alpha 45和alpha 48之间的http是否有任何重大变化?我一直在寻找,我没有找到任何东西.我的问题是下面的代码在Alpha 45上完美运行.但是现在我已经升级到Alpha 48,_this.http.post(...).map is not a function当我尝试运行应用程序时,我收到一条错误消息.奇怪的是,IntelliSense显示http.post正在返回一个可观察的.这意味着地图功能应该可用.任何帮助,将不胜感激.谢谢!

public Authenticate(username: string, password: string): Observable<boolean> {

    this.ResetAuthenticationValues();

    return Observable.create((subscriber: EventEmitter<string>) => { 

        let body: string = 'grant_type=password&username=' + username + '&password=' + password;
        let headers = new Headers();
        headers.append('Content-Type', 'application/x-www-form-urlencoded');

        this.http.post('http://example.com', body, {headers: headers})
            .map(res => res.json())
            .subscribe(
                (data: DataResponse) => {
                    if (!data.error) {
                        this.accessToken = {access_token: data.access_token, token_type: data.token_type};
                        subscriber.next(this.isAuthenticated = true);                       
                    }
                    else
                        subscriber.error(this.isAuthenticated = false);
                },
                (err) => subscriber.error(err),
                () => subscriber.complete()
            );

        return …
Run Code Online (Sandbox Code Playgroud)

rxjs typescript angular

13
推荐指数
3
解决办法
2万
查看次数

标签 统计

angular ×1

rxjs ×1

typescript ×1