本文介绍了角2的HTTP服务无法揭图()等函数RxJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有人知道,如果有一直阿尔法45和α48之间的任何HTTP重大更改?我一直在寻找周围,我没有发现任何东西。我的问题是低于code的Alpha上45完美工作,但现在我已经升级到阿尔法48我得到一个 _this.http.post(...)。地图不是一个函数当我尝试运行应用程序的错误消息。奇怪的是,智能感知显示http.post是返回一个可观察的。这意味着,在地图上的功能应该是可用的。任何帮助将是AP preciated。谢谢!

 公开进行身份验证(用户名:字符串,密码:字符串):可观察<布尔> {    this.ResetAuthenticationValues​​();    返回Observable.create((用户:EventEmitter<串GT)=> {        让身体:字符串='grant_type =密码&放大器;用户名='+用户名+'和;密码='+密码;
        让标题=新的报头();
        headers.append(Content-Type的','应用程序/ x-WWW的形式urlen codeD');        this.http.post('http://example.com',身体,{标题:标题})
            .MAP(RES => res.json())
            。订阅(
                (数据:DataResponse)= GT; {
                    如果(!data.error){
                        this.accessToken = {的access_token:data.access_token,token_type:data.token_type};
                        subscriber.next(this.isAuthenticated = TRUE);
                    }
                    其他
                        subscriber.error(this.isAuthenticated = FALSE);
                },
                (ERR)=> subscriber.error(ERR)
                ()=> subscriber.complete()
            );        回报()= GT; {};
    });
}


解决方案

另一个更新 (咳嗽,我们对此深感抱歉,忘了此选项)

如果你想避免做单独加入运营商可以导入完整的接收

从'rxjs /接收进口{观测,主题,ReplaySubject等..};

您将有所有操作员:)

更新阿尔法50 (2015年8月12日)

49字母被释放后不久,他们发布阿尔法50.此版本升级rxjs阿尔法14,所以你会好做去

NPM安装angular2 @最新
NPM安装[email protected]

更新阿尔法49 (2015年8月12日)

如现在的被释放,这并没有改变,这意味着这将保持时间。原始答案仍然有一些变化有效,路径改变rjxs,所以应该如下:

System.config({
    路径:{
        rxjs /添加/可观测/ *:node_modules / rxjs /添加/可观测/ * JS。,
        rxjs /添加/运营/ *':'node_modules / rxjs /添加/运营/ * JS',
        rxjs / *':'node_modules / rxjs / * JS
    }
});进口'rxjs /添加/运营/图;

注意

这个版本需要完全阿尔法13 的版本,所以如果你的的package.json 您已经另一个版本,你必须将其删除,安装angular2,然后再安装rjxs。

更新

的CHANGELOG已更新,以显示这个重大更改。有来自@jeffbcross 中的,在这个问题澄清了许多。

该意见的部分引用

Original answer

There was actually a breaking change regarding RxJS and Angular2. So now to use operators like map you have to import them separately. You can see the change in this pull request. And there's already an issue about your question.

I recommend you to stick to alpha 47. But to everyone who needs and want to know what the solution is, like in the pull request is specified, to add the operator separately.

You must have something like this

import {Http, ...} ...;

// Component
constructor(http: Http) {
    http.get(...).map() // 'map' doesn't exist! Ouch!
}

To fix it, add the operator (sorry for repeating it so many times) and configure the paths to rxjs

Note

This must be done with RxJS alpha 11, or alpha 12 (don't confuse it with @reactivex/rxjs, now it's just rxjs). So install it with

npm install [email protected]

Or just npm install rxjs if you want the latest, although they lock it to be alpha 11.

Configure the paths in your System.config (note that this is my config, not necessarily the best and I'm assuming you installed alpha 11)

System.config({
    paths: {
        'rxjs/observable/*' : 'node_modules/rxjs/observable/*.js',
        'rxjs/operators/*' : 'node_modules/rxjs/operators/*.js',
        'rxjs/*' : 'node_modules/rxjs/*.js'
    }
});

After you are done with the configuration, you can import the operator as follows

 import 'rxjs/operators/map';

And that's all. You'll have to do that with every operator. So I repeat, I recommend you to stick to alpha 47, like I told you in the comment. I will try to update the answer later with a plnkr.

这篇关于角2的HTTP服务无法揭图()等函数RxJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 03:41