gpt4 book ai didi

angular - 从 RXJS 5 迁移到 6 - IntervalObservable

转载 作者:太空狗 更新时间:2023-10-29 18:18:29 26 4
gpt4 key购买 nike

我从 RXJS 5.x 更新到 RXJS 6.2.2,遇到了解决迁移错误的问题。

RXJS 6 中不再有 IntervalObservables 了吗?我在以下 Angular 组件中使用了 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();
});
}
}

当我运行“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'.

仅供引用:我之前运行了命令rxjs-tslint auto update rules,它没有发现任何迁移问题!

最佳答案

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

ngOnInit() {
interval(1000).pipe(
takeWhile(() => this.alive)
.subscribe(() => {
this.today = Date.now();
});

rxjs 6 interval

关于angular - 从 RXJS 5 迁移到 6 - IntervalObservable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51688768/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com