felixo
felixo

Reputation: 1613

Angular 8: Property 'of' does not exist on type 'typeof Observable'

Any idea why I am getting this error in my Angular 8 application:

ERROR in src/app/_services/resolver.service.ts(13,23): error TS2339: Property 'of' does not exist on type 'typeof Observable'.

This is the way I have imported it:

import { Injectable } from '@angular/core';
import { Resolve } from '@angular/router';
import { Observable, of } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class ResolverService implements Resolve<Observable<string>> {

  constructor() { }

  resolve() {
    return Observable.of('Hello Resolver!').delay(2000);
  }
}

According to all the other threats I have seen pertaining to this I am doing it correctly as I understand. Thanks!

Upvotes: 1

Views: 5274

Answers (1)

Phix
Phix

Reputation: 9920

Observable.of was the older syntax. With "lettable" or "pipeable" operators, you import each individually and pipe them together. Not sure where delay is coming from but assuming you're importing it from rxjs/operators:

import { Injectable } from '@angular/core';
import { Resolve } from '@angular/router';
import { Observable, of } from 'rxjs';
import { delay } from 'rxjs/operators';

@Injectable({
  providedIn: 'root'
})
export class ResolverService implements Resolve<Observable<string>> {

  constructor() { }

  resolve() {
    return of('Hello Resolver!').pipe(delay(2000));
  }
}

Upvotes: 5

Related Questions