【问题标题】:Migration from Angular2 beta1 to Angular2 beta15 - .map() error从 Angular2 beta1 迁移到 Angular2 beta15 - .map() 错误
【发布时间】:2016-08-11 10:09:13
【问题描述】:

我正在尝试将项目从 Angular2 beta1 迁移到 Angular2 beta15,但遇到了一些问题。

我有错误消息:'map' 属性不存在于'Observable'

出现此错误的代码示例:

import { Injectable } from 'angular2/core';
import { Http, Response, Headers } from 'angular2/http';
import { Observable } from 'rxjs/Observable';
import { HelperModule } from './helpers.module';
import { BlogPost } from './model';
import 'rxjs/add/operator/map';

/**
 * Service dealing with blog data
 */
@Injectable()
export class DataService {

    constructor(private http: Http) { }

    /**
     * Call API to list available blog posts
     */
    listBlogPosts() {
        return this.http.get(HelperModule.UrlBuilder.BuildPostListUrl()).map(res => (<Response>res).json());
    }

}

代码在这里:https://github.com/AdrienTorris/AspNet5Angular2Playground

编辑:我正在使用 rxjs 5.0.0-beta6typescript 1.8.10,目标是 es6

【问题讨论】:

  • 地图装饰器适用于 rxjs 5.0.0-beta2

标签: typescript angular rxjs rxjs5 typescript1.8


【解决方案1】:

需要导入map操作符:

import 'rxjs/add/operator/map';

或所有运营商:

import 'rxjs/Rx';

看到这个问题:

【讨论】:

【解决方案2】:

尝试使用最新版本的 Typescript (1.9) 来编译您的代码。模块扩充在 TS 1.8 的一些次要版本中存在错误。 RXJS 在 5.0.0-beta2 之后改变了它定义模块的方式。

您可以使用以下方式尝试夜间构建:npm install -g typescript@next

【讨论】:

    猜你喜欢
    • 2016-08-26
    • 1970-01-01
    • 2019-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-29
    • 1970-01-01
    相关资源
    最近更新 更多