Getting the error ../node_modules/rxjs/Rx"' has no exported member 'of'

后端 未结 1 1341
清歌不尽
清歌不尽 2021-02-05 04:26

I\'m learning new angular from the tutorial(https://angular.io/tutorial/toh-pt4#inject-message-service). I\'m stuck in this while running the application after adding the Servic

1条回答
  •  鱼传尺愫
    2021-02-05 05:06

    From your code it looks like you are following Angular official guide which is based on Angular 6 and Rxjs 6. There is a breaking change in Rxjs for which you have to import operators and Observable in a different way now .

    In Rxjs 6 the import is like below -

    import { Observable, of } from 'rxjs'; // only need to import from rxjs
    

    But as you are using Angular 5.2.x most probably you are still using Rxjs 5x version. Due to which your import statement should be like below

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

    Check the below link for complete changelog and instruction to install a compatibility package rxjs-compat for upgrading from angular 5 to 6.

    See this link for reference : https://www.academind.com/learn/javascript/rxjs-6-what-changed/

    0 讨论(0)
提交回复
热议问题