类型“typeof Observable"上不存在属性“from",角度为 6? [英] Property 'from' does not exist on type 'typeof Observable', angular 6?
本文介绍了类型“typeof Observable"上不存在属性“from",角度为 6?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将 angular 5.2.10 项目更新为 angular 6.
我一步一步https://update.angular.io/
,一切正常,除非Observable.from
在一个服务中,我使用了 Observable.from(this.user)
如下:
I updated my angular 5.2.10 project to angular 6.
I did step by step https://update.angular.io/
, everything is OK unless Observable.from
In a service I used Observable.from(this.user)
as following:
import { Observable } from 'rxjs/Observable';
...
Observable.from(this.users)// this.users is an array
没问题,但在 angular 6 中出现以下错误
It was OK, but in angular 6 the following error occurred
Property 'from' does not exist on type 'typeof Observable'
我改成如下
import { Observable, from } from 'rxjs';
但是没有变化,错误又发生了!
But no change and error occurred again!
推荐答案
在 rxjs@6 中,您可以使用 from
作为独立函数:
In rxjs@6 you can use from
as standalone function:
import { from } from 'rxjs';
...
from(this.users);
或
import { from as observableFrom } from 'rxjs';
...
observableFrom(this.users);
另见迁移到 rxjs6 指南
See also migration to rxjs6 guide
这篇关于类型“typeof Observable"上不存在属性“from",角度为 6?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文