Angular 2:“Observable<Response>"类型上不存在属性“toPromise" [英] Angular 2: Property 'toPromise' does not exist on type 'Observable<Response>'
问题描述
我正在开发 Angular 2 项目并遵循 Http 客户端指南 用于实现 HTTP 请求但在使用 RsJx
模块时收到以下错误.
I'm developing Angular 2 project and following Http Client Guide for implementing HTTP request But receiving following error when using RsJx
module.
'Observable' 类型不存在属性 'toPromise'
Property 'toPromise' does not exist on type 'Observable'
我已完成以下操作,但错误仍然存在:
I have done the following but error still persist:
- 添加
import 'rxjs/add/operator/toPromise'
;到服务模块 - 检查
RxJs
库的版本是否有任何依赖项. - 从
RxJs库
导入所有模块
- Added
import 'rxjs/add/operator/toPromise'
; to service module - Checked the version of
RxJs
library for any dependency. - imported all modules from
RxJs library
您可以在 Github 上此处找到我的源代码.请指导我应该做什么以及我缺少什么.谢谢.
You can find my source code here on Github. Please guide what should I do and what I'm missing. Thank you.
你可以在 rxjs-operators.ts 文件中找到所有的导入,我已经在 app.component.ts 文件中引用了它以使其成为全局但我仍然是dragon.service.ts 文件出错.此外,.map() 也显示相同的错误.
You can find all the imports in rxjs-operators.ts file and I have referenced it in app.component.ts file to make it global BUT still I am having error in dragon.service.ts file. Moreover, same error is shown for .map() as well.
您可以在 package.json 文件中找到所有版本详细信息.
You can find all the version details in package.json file.
其他详细信息是:
- 节点版本:v4.4.7
- npm 版本:v3.10.5
- 角度版本:2.0.0-rc.4
- RxJs 版本:5.0.0-beta.6
注意: 目前我已经对代码进行了注释,但您可以根据需要进行修改.
推荐答案
请查看:Angular 22.0.0-rc.1 属性 'map' 不存在于类型 'Observable
对于 VS 2015(更新 3):
"For VS 2015 (Update 3):
安装 VS 2015 Update 3 用 https://raw.githubusercontent.com/Microsoft/TypeScript/Fix8518-U3/lib/typescriptServices.js.不过,请先进行本地备份."
Install VS 2015 Update 3 Replace C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TypeScript\typescriptServices.js with the file in https://raw.githubusercontent.com/Microsoft/TypeScript/Fix8518-U3/lib/typescriptServices.js. First take a local backup though."
此解决方法为我解决了属性 'toPromise' 不存在"的问题.
This workaround fixed the "Property 'toPromise' does not exist " issue for me.
这篇关于Angular 2:“Observable<Response>"类型上不存在属性“toPromise"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!