Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not use Observable.of in RxJs 6 and Angular 6

 import { Observable, of } from "rxjs";  // And if I try to return like this   return Observable.of(this.purposes); 

I am getting an error stating, Property 'of' does not exist on type 'typeof Observable'

like image 742
Harish Krishnan Avatar asked May 07 '18 19:05

Harish Krishnan


People also ask

How are RxJS observables used in angular?

Angular is a popular front-end framework made by Google. Like other popular front-end frameworks, it uses a component-based architecture to structure apps. In this article, we’ll look at how Rxjs observables are used in Angular. The EventEmitter class that’s used to send data from child to parent components uses observables to transmit the data,

What are the challenges of working with RxJS observables?

One of the first challenges you’ll face when working with RxJS Observables is getting them to execute in a specific order. On the surface, this seems like a straightforward goal, but, when it comes to asynchronous processes, nothing is ever simple. Even if observables are executed in succession, they won’t necessarily emit values in the same order.

What is a subscriber in RxJS in angular?

This article on RxJS in Angular is part of the Learning Angular series. A subscriber takes in 3 parameters as follows: For the custom Observables created in the previous lectures, if one navigates out of the page holding the Observables, one would notice that the Observables are still active and continue to emit.

What is the difference between observable and subject in angular?

Subject is extended from Observable and it implements both the Observer and the Subscriber. This makes it easy to use. Note: Angular EventEmitter is based upon Subject, but it is preferable to use the Subject instead of EventEmitter to perform cross-component communication.


2 Answers

Looks like cartant's comment is correct, the RxJS upgrade guide doesn't cover that method specifically but does say "Classes that operate on observables have been replaced by functions"

Which seems to mean all or most of those class methods like .of, .throw etc. have been replaced by a function

So instead of

import { Observable, of } from "rxjs"; Observable.of(this.purposes); 

do

import { of } from "rxjs"; of(this.purposes); 
like image 147
tim545 Avatar answered Sep 21 '22 07:09

tim545


rxjs 6

import { PreloadingStrategy, Route } from '@angular/router'; import { Observable, of } from 'rxjs';  export class SelectivePreloadingStrategy implements PreloadingStrategy {     preload(route: Route, load: Function): Observable<any> {        return route.data && route.data.preload === false ? of(null) : load();     }   } 
like image 30
Tiny King Avatar answered Sep 21 '22 07:09

Tiny King