从 RXJS 5 迁移到 6 - IntervalObservable

d4r*_*rty 3 rxjs angular

我从 RXJS 5.x 更新到 RXJS 6.2.2 并且在解决迁移错误时遇到问题。

RXJS 6 中不再有 IntervalObservables 了吗?我在以下角度组件中使用了 IntervalObservable

import {Component, OnInit} from '@angular/core';
import {IntervalObservable} from 'rxjs/observable/IntervalObservable';

@Component({
  selector: 'app-date-time-display',
  templateUrl: './date-time-display.component.html',
  styleUrls: ['./date-time-display.component.css']
})
export class DateTimeDisplayComponent implements OnInit {

  constructor() {
  }

  today = Date.now();

  ngOnInit() {
    IntervalObservable.create(1000)
    // .takeWhile(() => this.alive) // only fires when component is alive
      .subscribe(() => {
        this.today = Date.now();
      });
  }
}
Run Code Online (Sandbox Code Playgroud)

当我运行“ng serve”或“ng build”时,出现以下错误:

Module not found: Error: Can't resolve 'rxjs/observable/IntervalObservable' in 'C:\Users\Daniel\Documents\IMA\Porsche_lack\git\webapp\porsche-lack-tracking\src\app\date-time-display'
i ?wdm?: Failed to compile.
ERROR in node_modules/rxjs/observable/IntervalObservable.d.ts(1,15): error TS2307: Cannot find module 'rxjs-compat/observable/IntervalObservable'.
Run Code Online (Sandbox Code Playgroud)

仅供参考:我rxjs-tslint auto update rules之前运行过该命令,但没有发现任何迁移问题!

jos*_*sip 5

import { interval } from 'rxjs';
import { takeWhile } from 'rxjs/operators';

ngOnInit() {
    interval(1000).pipe(
       takeWhile(() => this.alive)
    .subscribe(() => {
        this.today = Date.now();
    });
Run Code Online (Sandbox Code Playgroud)

rxjs 6 间隔