angular6 – Angular 6属性’map’在’Object’类型上不存在

前端之家收集整理的这篇文章主要介绍了angular6 – Angular 6属性’map’在’Object’类型上不存在前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个api,返回像这样的对象/数组:

(2) [{...},{...}]      object

  0: {a: '1',b: {id: '1'}}
  1: {a: '2',b: {id: '2'}}

所以它看起来像对象的数组(但是debuges说’对象’).

所以在我的代码中我有:

return this.http.get(this.url).pipe(
  map(datas => {
    return datas.map(data => {
      let object = {
        a: data['a'],b: data['b']['id'],}
      return object;
    })
  })
);

但那里:

return datas.map(data => {

我收到一个错误

Property 'map' does not exist on type 'Object'.

但应用程序运行良好是正确显示此数据.但这个错误很烦人.

我能做什么?

解决方法

以下运算符在RXJS6中重命名

catch() => catchError()
do() => tap()
finally() => finalize()
switch() => switchAll()

此外,一些Observable创建方法重命名/重构:

throw() => throwError()
fromPromise() => from() (this automatically detects the type)

FOR MAP语法

import { map } from 'rxjs/operators';

myObservable
  .pipe(map(data => data * 2))
  .subscribe(...);

猜你在找的Angularjs相关文章