Error: Can't resolve 'rxjs/add/operator/map'

前端 未结 4 1423
甜味超标
甜味超标 2020-12-29 23:54

This is app.module.ts I have tried to done the Import of map in different project and it worked fine, but in this project it\'s not working.

            


        
相关标签:
4条回答
  • 2020-12-30 00:16

    The newer versions of Angular does not support map. So you need to install it using the command prompt using the following command. First go the the project directory and use the command:

    npm install --save rxjs-compat
    

    Don't forget to import this:

    import 'rxjs/add/operator/map';
    

    Thanks!

    0 讨论(0)
  • 2020-12-30 00:20

    In angular 6 import 'rxjs/add/operator/map'; become to:

    import { map } from 'rxjs/operators';
    

    Read here:https://www.academind.com/learn/javascript/rxjs-6-what-changed/

    0 讨论(0)
  • There are some pretty heavy change in the use of rxjs 6.

    Imports :

    As already stated, you should now use :

    import { map } from 'rxjs/operators';
    

    (and same for other operators)

    I want to mention here the other main changes :

    Observable, Subject and methods that create Observables (like of) have now to be imported like that :

    import { Observable, of, Subject } from 'rxjs';
    

    You will need to use pipe to apply most operators, which might look a bit strange.

    e.g. :

    obs.pipe(
        map(....),
        secondOperator(....),
        thirdOperator()
    )
    

    instead of

    obs.map(....)
       .secondOperator(....)
       .thirdOperator()
    

    And finally, due to the change with pipe and conflict with JavaScript reserved words, some operators had to be renamed :

    do becomes tap

    catch and finally become catchError finalize

    switch becomes switchAll

    other functions were renamed as well :

    fromPromise becomes from

    throw becomes throwError

    0 讨论(0)
  • 2020-12-30 00:30

    import { from } from 'rxjs'; import { filter } from 'rxjs/operators';

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