类型"Observable< Response>"上不存在属性"map"当使用角度版本2.4.9时,打字稿& webpack版本2.2.1 [英] Property 'map' does not exist on type 'Observable<Response>' when using angular version 2.4.9, typescript & webpack version 2.2.1

查看:61
本文介绍了类型"Observable< Response>"上不存在属性"map"当使用角度版本2.4.9时,打字稿& webpack版本2.2.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Angular 2应用程序访问Web api方法,我能够使用Web api获取记录.但是问题是,显示属性'map'的service.ts文件在类型为'Observable'时不存在错误.

I am trying to access web api methods from Angular 2 application, i am able to get the records using web api. But the problem is, service.ts file showing Property 'map' does not exist on type 'Observable' error.

示例代码:

    import { Injectable } from '@angular/core';
    import { Http } from '@angular/http';
    import { Observable } from 'rxjs/Observable';
    import 'rxjs/Rx';

    @Injectable()
    export class ContactServices 

    {

        private url = 'http://localhost:51498/api/test/';
        constructor(private http: Http) { }

        getContacts():Observable<Object[]> {
            return this.http.get(this.url + 'GetContacts')
                .map(response => response.json())
                .catch(error => {
                    console.log(error);
                    return Observable.throw(error);
                });
        }

        getContactById(id: number) {
            return this.http.get(this.url + 'GetContactList/' + id)
                .map(response => <Contact[]>response.json())
                .catch(error => {
                    console.log(error);
                    return Observable.throw(error);
                });
        }
    }

export class Contact {
    Id: number;
    Name: string;
    Details: string;
}

我正在使用以下版本,

  1. webpack 2.2.1
  2. 角度2.4.9
  3. 节点6.10.0
  4. npm 4.1.2
  5. 打字稿2.2.1

推荐答案

问题是 TypeScript 版本.我已经提到过,它是 2.2.1 版本,但是我的系统具有 1.8.3 版本.因此只有问题发生了.感谢谁和所有人都审查了这个问题.

The problem is TypeScript version. I have mentioned that, it is 2.2.1 version but my system is having 1.8.3 version. So only the problem occur. Thanks for who and all reviewing this problem.

这篇关于类型"Observable&lt; Response&gt;"上不存在属性"map"当使用角度版本2.4.9时,打字稿&amp; webpack版本2.2.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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