【问题标题】:Not able to use map function无法使用地图功能
【发布时间】:2018-05-25 18:23:12
【问题描述】:
    import { Injectable } from '@angular/core';
    import { Http,Headers } from '@angular/http';
     import { List } from '../models/List'
     import {Observable} from 'rxjs/Rx';
     import 'rxjs/add/operator/map';

     @Injectable()
export class ListService {

    constructor(private http: Http) { }

    private serverApi= 'http://localhost:3000';

    public getAllLists():Observable<List[]> {

        let URI = `${this.serverApi}/bucketlist/`;
        return this.http.get(URI)
            .map(res => res.json())

            .map(res => <List[]>res.lists);
    }

    public deleteList(listId : string) {
      let URI = `${this.serverApi}/bucketlist/${listId}`;
        let headers = new Headers;
        headers.append('Content-Type', 'application/json');
        return this.http.delete(URI, {headers})
        .map(res => res.json());
    }
}

我收到错误 属性映射在 Observable 类型上不可用,请大家帮忙

【问题讨论】:

  • 你用的是什么 rxjs 版本?
  • 我正在使用 6.2.0 版本的 rxjs 我在 2 个月前开始使用 Angular 再次编码,但现在它显示错误
  • 你为什么要使用HttpModule,它已被弃用,而是使用HttpClientModule

标签: angular


【解决方案1】:

恕我直言,您使用的是旧语法。

执行以下操作:

import { map } from 'rxjs/operators';

然后:

this.myObservableFunctionCall().pipe(map(data => {}))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-12
    • 1970-01-01
    相关资源
    最近更新 更多