I am working with angular services and I got an error which is caused by BehaviorSubject
.
Error
Module '"ng5/node_modules/rxjs/BehaviorSubject"' has no exported member 'BehaviorSubject'.
data.service.ts
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
@Injectable()
export class DataService {
constructor() { }
}
if you want to import all RxJS
just do :
import { BehaviorSubject } from 'rxjs';
If you only need BehaviorSubject
:
import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
EDIT : Explication
On ES6 / TypeScript all import
is related to export
keyword. If you go on node_modules/rxjs/index.d.ts
you will see all exported Class.
This means what ever see as exported on this file can be imported as : import { SomeThing } from 'rxjs';
But, your generated bundle file will inclure all RxJS stuff including unnecessary part of this library.
To avoid that, i recommand you to import from : from 'rxjs/internal/SomeThing'
(replace SomeThing by what you need)
For operators, you can find it on from 'rxjs/internal/operators/SomeThing'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With