角8:属性“ of”在类型“ typeof Observable”上不存在

时间:2020-04-13 18:41:31

标签: angular typescript observable

任何想法为何我在Angular 8应用程序中都会收到此错误:

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

这是我导入它的方式:

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);
  }
}

根据我所看到的与此相关的所有其他威胁,据我所知,我正在正确地进行操作。谢谢!

1 个答案:

答案 0 :(得分:3)

Observable.of是较旧的语法。使用“ lettable”或“ pipeable”运算符,可以分别导入每个并将其通过管道传输。不确定delay的来源,但假设您是从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));
  }
}