首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >类型'Subscription‘缺少类型’Subscription‘的以下属性:_parentOrParents,_subscriptions

类型'Subscription‘缺少类型’Subscription‘的以下属性:_parentOrParents,_subscriptions
EN

Stack Overflow用户
提问于 2021-11-25 13:12:54
回答 1查看 199关注 0票数 0

我得到了上面提到的错误与我的角度ts文件。但不能理解并修复。有人能帮我吗?

ts文件:

代码语言:javascript
复制
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();
  }

}
EN

回答 1

Stack Overflow用户

发布于 2021-11-25 15:12:48

也许scully-route-service使用了不同版本的rxjs。作为解决方案,您可以使用rxjs管道操作符takeUntil和一个用于取消订阅的主题,而不是保存订阅的实例。下面是示例代码:

代码语言:javascript
复制
onDestroy$: Subject<boolean> = new Subject();

ngOnInit() {
 this.scullyService.available$.pipe(takeUntil(this.destroy$)).subscribe(() => 
{ //do stuff 
})
this.service.someSubscriber2.pipe(takeUntil(this.destroy$)).subscribe(() => 
{ //do stuff 
})
this.service.someSubscriber3.pipe(takeUntil(this.destroy$)).subscribe(() => 
{ //do stuff 
})
}

ngOnDestroy() {
  this.destroy$.next(true);
  this.destroy$.unsubscribe();
}

或者你可以通过升级到angular 13来解决问题的核心,这将是最好的选择。如果你不能升级到13,我建议将你的scully版本降级到支持angular 12的版本。

如果您没有考虑升级到angular 13,那么支持RX6的scully的LTS版本是1.1.4:https://registry.npmmirror.com/@scullyio/init/1.1.4?spm=a2c6h.24755359.0.0.60394d45aVQlxP&file=1.1.4

您可以通过运行npm install @scullyio/init@1.1.4来安装它

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70111750

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档