【发布时间】:2018-09-18 12:23:41
【问题描述】:
我已将我的应用程序从 angular 4 升级到 angular 6。我遇到了错误 subscribe 在 observable 类型上不存在。有人可以告诉我角度 6 是否有任何变化
import { Injectable } from '@angular/core';
import { Dto, ApiResult } from '../api';
import { RunsProxy } from '../api/proxies';
import { Observable, ReplaySubject, Subject } from 'rxjs';
import { AlertService } from './alert.service';
import { TranslateService } from '@ngx-translate/core';
import { ReadonlyProvider } from '@wtw/toolkit/src/directives/read-only-inputs.directive';
import { Router, NavigationStart, NavigationCancel, NavigationEnd } from '@angular/router';
import { CurrencyInfo, RunExecution } from '../api/dtos';
import { tap , map, share, delay } from 'rxjs/operators'
import { fireAndForget } from "platform/tests/helpers";
*public load(id: number): Observable<ApiResult<Dto.RunModel>> {
const obs = this._runs.get(id).uiSignal('load run').share();
obs.subscribe(ret => {
if (!!!ret.data && this.blnShown === false) {
this.blnShown = true;
this._translate.get('GLOBAL.TOASTS.RUN_UNAVAILABLE').subscribe(o => {
this._alertService.error(o);
});
}
this._activeRun.next(ret.data);
}, err => {
if (err.status === 403 || err.status === 404) {
this._router.navigate(['/home']);
this._alertService.clear();
this._translate.get('GLOBAL.TOASTS.RUN_UNAVAILABLE').subscribe(o => this._alertService.error(o));
} else throw err;
});
return obs;
}*
【问题讨论】:
-
在迁移到 Angular 6 之前,您的 rxjs 版本是多少?如果不是 6,那么您可能需要运行以下命令
npm install rxjs@6 rxjs-compat@6 --save并保存 rxjs-compact -
你好 Rajeev,我不想安装 rxjs-compat 并走那条路。而是想更改我的代码以使用新版本。它是第 4 版,现在是第 6 版
标签: angular