【发布时间】:2022-01-03 18:25:33
【问题描述】:
我的 Angular ts 文件出现上述错误。但无法理解修复。谁来帮帮我
ts 文件:
import { Component, OnInit, OnDestroy } from '@angular/core';
import { ScullyRoute, ScullyRoutesService } from '@scullyio/ng-lib';
import { Subscription } from 'rxjs';
@Component({
selector: 'app-articles',
templateUrl: './articles.component.html',
styleUrls: ['./articles.component.scss']
})
export class ArticlesComponent implements OnInit, OnDestroy {
posts: ScullyRoute[] = [];
private routeSub: Subscription | undefined;
constructor(private scullyService: ScullyRoutesService) { }
ngOnInit(): void {
this.routeSub = this.scullyService.available$.subscribe(posts => {
this.posts = posts.filter(post => post.title);
});
}
ngOnDestroy(): void {
this.routeSub?.unsubscribe();
}
}
【问题讨论】:
-
你能添加服务的定义,特别是
available$。那是 Observable、BehaviorSubject、Subject...? -
尝试用
private routeSub!: Subscription;替换private routeSub: Subscription | undefined; -
听起来你有多个版本的 RxJS。
-
据我了解,rxjs 7 与以前的版本相比有一些相当大的变化。我不认为 angular 12.x 支持 rxjs 7。here 上有一个线程。我知道 angular 13 确实支持它。如果您能够升级到 13,那将是最好的选择。如果您无法升级到 13,我建议将您的
scully版本降级到支持 Angular 12 的版本。RXJS 是 Angular 的核心功能,因此在不支持它的 Angular 版本上盲目升级它会有风险
标签: angular typescript typeerror angular-scully