Observable.of is not a function

后端 未结 19 605
旧时难觅i
旧时难觅i 2020-11-30 19:41

I am having issue with importing Observable.of function in my project. My Intellij sees everything. In my code I have:

import {Observable} from          


        
相关标签:
19条回答
  • 2020-11-30 20:31

    Somehow even Webstorm made it like this import {of} from 'rxjs/observable/of'; and everything started to work

    0 讨论(0)
  • 2020-11-30 20:33

    RxJS 6

    When upgrading to version 6 of the RxJS library and not using the rxjs-compat package the following code

    import 'rxjs/add/observable/of';   
      // ...
      return Observable.of(res);
    

    has to be changed into

    import { of } from 'rxjs';
      // ...
      return of(res);
    
    0 讨论(0)
  • 2020-11-30 20:33

    In rxjs v6, of operator should be imported as import { of } from 'rxjs';

    0 讨论(0)
  • 2020-11-30 20:34

    I had this problem today. I'm using systemjs to load the dependencies.

    I was loading the Rxjs like this:

    ...
        paths: {
            "rxjs/*": "node_modules/rxjs/bundles/Rx.umd.min.js"
        },
    ...
    

    Instead of use paths use this:

    var map = {
    ...
    'rxjs':                       'node_modules/rxjs',
    ...
    }
    
    var packages = {
    ...
    'rxjs': { main: 'bundles/Rx.umd.min.js', defaultExtension: 'js' }
    ...
    }
    

    This little change in the way systemjs loads the library fixed my problem.

    0 讨论(0)
  • 2020-11-30 20:35

    This should work properly just try it.

    import { Observable } from 'rxjs/Observable';
    import 'rxjs/add/observable/of';
    
    0 讨论(0)
  • 2020-11-30 20:37

    Actually I have imports messed up. In latest version of RxJS we can import it like that:

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