Reputation: 2415
Im building service that should temporarily return Observable of some array before the server API will constructed. Before upgrading to angular and other packages to 6.0.0-rc.3 version i used following syntax:
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
@Injectable()
export class GeocodesService {
getPositions():Observable<any>{
return Observable.of({ })
}
}
At 6.0.0-rc.3, this syntax looks deprecated Trying to import it following way (using latest angular):
import 'rxjs/observable/of'
But Getting error:
Module not found: Error: Can't resolve 'rxjs/observable/of'
How import of "of" can be done with latest rxjs?
Thanks
Upvotes: 7
Views: 8521
Reputation: 757
Using :
import {of} from 'rxjs';
throw error in Angular v6 or 6+
use like this:
import {of as useOf } from 'rxjs';
............... .... ..............
getBooks():Observable<Book[]>{
return useOf(this.BOOKS);
}
Error Solved!!!
Upvotes: 0
Reputation: 246
You must change your imports and your instantiation. Check out Damien's blog post
Tl;dr:
import { Observable, fromEvent, of } from 'rxjs';
const yourResult = Observable
.create(of(yourObservable))
.startWith(null)
.map(x => x.someStringProperty.toLowerCase());
//subscribe to keyup event on input element
Observable
.create(fromEvent(yourInputElement, 'keyup'))
.debounceTime(5000)
.distinctUntilChanged()
.subscribe((event) => {
yourEventHandler(event);
});
Upvotes: 1
Reputation: 58440
If you want to use the patching imports with RxJS version 6, you will also need to install rxjs-compat
.
It's a separate package that adds backwards compatibility (with RxJS version 5) to RxJS version 6:
npm install [email protected]
With rxjs-compat
installed, your patching imports should work just fine.
For more information, see the migration guide.
Upvotes: 5
Reputation: 2415
Finally found the solution here
This guy (Tomas Trajan), uses following syntax:
import { Observable , of} from 'rxjs'
and after you can use:
getWidgets() {
return of([]);
}
Upvotes: 9