0
votes

I am trying to return a value inside a function that in turn return an observable but I am getting this error.

Property 'of' does not exist on type 'typeof Observable'.

can this be done without using Observable.of() method

import { Component, OnDestroy, OnInit } from '@angular/core';

 import { interval, Subscription, Observable , of } from 'rxjs';

@Component({
  selector: 'app-home',

  templateUrl: './home.component.html',

  styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit,OnDestroy {

  count:number = 10;

  private firstObsSubscription : Subscription;

  constructor() { }

  ngOnInit() {
  
   this.customObservable().subscribe((data:boolean)=>{

    console.log(data);

      })
  }

  customObservable():Observable<boolean>{

    if (this.count === 10 ){

      return Observable.of(true);

    }

 }

  ngOnDestroy(){

    this.firstObsSubscription.unsubscribe();

  }

}
1
Hey, what version of rxjs are you using?jburtondev

1 Answers

1
votes

If you are using Angular 8+

Change this part:

  customObservable():Observable<boolean>{

    if (this.count === 10 ){
      return of(true);
    }

Observable.of is part of Angular 7

If you are using Angular 6 /7

import { of } from 'rxjs';

And then instead of calling

Observable.of(true);