Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find module 'rxjs/subject/BehaviorSubject'

I am using Angular 2.

When I use either of these two, my program runs well:

import { BehaviorSubject } from 'rxjs/Rx'; import { BehaviorSubject } from 'rxjs'; 

However, I try to use the following way:

import { BehaviorSubject } from 'rxjs/subject/BehaviorSubject'; 

But I failed, my browser console shows:

Uncaught Error: Cannot find module 'rxjs/subject/BehaviorSubject'

How can I use third way correctly? Thanks

like image 659
Hongbo Miao Avatar asked Apr 18 '16 17:04

Hongbo Miao


People also ask

Can not find module RxJS?

To solve the error "Cannot find module 'rxjs-compat/Observable'", make sure to install the package by opening your terminal in your project's root directory and running the following command: npm i rxjs and restart your IDE and development server. Copied!

What is RxJS BehaviorSubject?

BehaviorSubject is a variant of a Subject which has a notion of the current value that it stores and emits to all new subscriptions. This current value is either the item most recently emitted by the source observable or a seed/default value if none has yet been emitted.

How do I use BehaviorSubject?

1. First create a BehaviorSubject in order service which holds the initial state of order count ,so that it can be used by any component. 2. Now all observers(3 components) need to subscribe to source observable to get current value and show it on UI.


1 Answers

import {BehaviorSubject} from 'rxjs/BehaviorSubject'; 

rxjs 6.x

import {BehaviorSubject} from 'rxjs'; 

See also

  • Property 'of' does not exist on type 'typeof Observable
  • https://stackoverflow.com/a/49665105/3232832
like image 144
Günter Zöchbauer Avatar answered Sep 17 '22 20:09

Günter Zöchbauer