【发布时间】:2019-08-01 04:16:10
【问题描述】:
我在构建 JHipster Angular 项目时遇到此错误。它发生在命令yarn start
import { Component, OnInit, OnDestroy } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { HttpResponse, HttpErrorResponse } from '@angular/common/http';
import { Subscription } from 'rxjs/Subscription';
import { JhiEventManager, JhiParseLinks, JhiAlertService } from 'ng-jhipster';
import { ITEMS_PER_PAGE, Principal } from '../../shared';
import { Observable } from 'rxjs/Observable';
....
private subscription: Subscription;
private eventSubscriber: Subscription;
...
ngOnInit() {
this.subscription = this.route.params.subscribe((params) => {
this.load(params['id']);
});
}
> TS90010: Type 'Subscription' is not assignable to type 'Subscription'.
> Two different types with this name exist, but they are unrelated.
但它以前可以正常工作。我不知道为什么会这样。
【问题讨论】:
-
能否提供出现错误的代码?从两条错误线很难说。
-
@JosefKatič 我提供了来自出现错误的许多组件之一的代码。
-
我的直觉告诉我你保存订阅以在 ngOnDestroy 中取消订阅。由于它是 Angular 原生的,因此您不需要这样做,因此您可能会跳过那段代码,除非您有其他用途。此外,您可以从 'rxjs' 导入 Observable 和 Subscription
-
@YuriiBidiuk 你确定你在任何地方都从同一个源导入
Subscription吗?
标签: angular typescript rxjs yarnpkg