'错误'消息:'类型'可观察'类型上不存在'属性'来自' [英] 'Error' message: 'Property 'from' does not exist on type 'typeof Observable'

查看:86
本文介绍了'错误'消息:'类型'可观察'类型上不存在'属性'来自'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用RxJS学习反应式编程.我试图使用 Observable.from()方法从数组创建可观察对象,但出现错误:

I am trying to learn reactive programming using RxJS. I was trying to create an observable from an array using Observable.from() method, but I am getting an error:

类型可观察"类型上不存在来自"属性

Property 'from' does not exist on type 'typeof Observable'

我使用Angular CLI搭建了Angular应用程序,因此包括RxJS包在内的所有依赖项都已正确导入.

I scaffolded an Angular application using Angular CLI, so all the dependencies including RxJS package was imported correctly.

app.component.ts 中,我添加了以下导入语句:

In app.component.ts I added below import statements:

import { Observable} from 'rxjs/Observable'
import 'rxjs/observable/from'

我的AppComponent类如下:

And my AppComponent class looks like this:

export class AppComponent {

  numbers: number[] = [1, 2, 3, 4, 5];

  callMyObservable() : void {  
    Observable.from(this.numbers);
  }
}  

但是我遇到了上面提到的编译时错误.

But I am getting the above mentioned compile time error.

我不确定如何使它工作.

I am not sure how to make it work.

推荐答案

更改

import { Observable} from 'rxjs/Observable'
import 'rxjs/observable/from'

收件人

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/from';

这篇关于'错误'消息:'类型'可观察'类型上不存在'属性'来自'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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