为什么会出现错误“类型'Observable< Response>''上不存在属性'map'"? [英] Why do I get the error "Property 'map' does not exist on type 'Observable<Response>'"?

查看:104
本文介绍了为什么会出现错误“类型'Observable< Response>''上不存在属性'map'"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是针对在Intellij15上运行有打字稿的angular2项目.我已经导入了"rxjs/add/operator/map",但是仍然出现上述错误. 这是我的代码.我在SO上检查了其他类似的问题,但没有找到解决方法.

This is for an angular2 project with typescript running on Intellij15. I have imported 'rxjs/add/operator/map', but I still get the above error. This is my code. I have checked other similar questions on SO, but have not found a solution.

import {Component, OnInit} from "@angular/core";
import {Http} from "@angular/http";
import 'rxjs/add/operator/map';

@Component({
    selector: "h-recommend",
    template:`
    <div>
        hi
    </div>
    `
})

export class Recommendations implements OnInit{

    constructor (private _http: Http){}

    ngOnInit():any {

        this._http.get('../jsonfile/guestRecommendations/1.json')
            .map(res => res.json())
            .subscribe((data) => {
                this.hello();
                alert(data);
            });
    }

     hello(){
        alert("hello");
    }

}

推荐答案

由于它是在编译时发生的,我想您没有es6-shim/core-js的类型.

Since it happens at compilation, I guess that you don't have the typings for es6-shim / core-js.

您在typings.json文件中需要此文件:

You need this in your typings.json file:

{
  "globalDependencies": {
     "core-js": "registry:dt/core-js#0.0.0+20160317120654", // <-------
     "jasmine": "registry:dt/jasmine#2.2.0+20160505161446",
     "node": "registry:dt/node#4.0.0+20160509154515"
  }
}

您可以使用typings install命令安装这些类型.

You can install these typings using the typings install command.

请参阅此页面以获取更多详细信息:

See this page for more details:

这篇关于为什么会出现错误“类型'Observable&lt; Response&gt;''上不存在属性'map'"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆