'Error' message: 'Property 'from' does not exist on type 'typeof Observable'

前端 未结 2 1263
广开言路
广开言路 2021-02-20 00:08

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 err

相关标签:
2条回答
  • 2021-02-20 00:18

    If you are using rxjs >=6.0.0 then you no longer use Observable.from. Instead from is a standalone function.

    import { Observable, from} from 'rxjs';
    
    //old way
    var o = Observable.from([1, 2, 3, 4]);
    
    //new way
    var o = from([1, 2, 3, 4]);
    

    I hope this is helpful since it took me a while to figure this out.

    0 讨论(0)
  • 2021-02-20 00:26

    Change

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

    To

    import { Observable } from 'rxjs/Observable';
    import 'rxjs/add/observable/from';
    
    0 讨论(0)
提交回复
热议问题