在将我的应用程序从角度5迁移到6之后,rxjs已经引起了各种各样的问题 . 我在迁移过程中和删除它之后使用了rxjs-compact,因为它会导致更大的内存利用率 . 我一直有这样的错误 .
._node_modules/rxjs-compat/_esm5/add/operator/publishReplay.js中的错误 . 模块构建失败:错误:ENOENT:没有这样的文件或目录,打开'/ home / training / Desktop / vishnu / TemplateAppv6 / node_modules / rxjs -compat / _esm5 /添加/运营/ publishReplay.js'
我尝试从rxjs和rxjs /运算符导入publishReplay .
从'rxjs / operators'导入{filter,map,catchError,publishReplay};
但是问题仍然存在,对于像catchError这样的publishReplay是否有任何变化 .
任何帮助,将不胜感激 .
这是完整的代码
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
import { ErrorResponse } from '../core/interfaces/Error';
import { throwError, ReplaySubject } from 'rxjs';
import { filter, map, catchError, publishReplay } from 'rxjs/operators';
import 'rxjs/add/observable/forkJoin';
import { environment } from '../../environments/environment';
import { HomeConstants } from './home-consatant';
import { BaseService } from '../core/base.service';
// Construct the rail data.
responses.map((response: RailResponse) => {
railsData[response.railId] = response
.entries
.map((entry: EntriesEntity) => {
return {
imageSrc: this.getImageUrl(entry, response.railId), // Get rail image according to the rail type.
contentTypeLabel: entry.pricingType, // Content Type.
description: entry.title, // Rail title.
url: '/details/' + entry.programType + '/' +
this.utility.encodeProgramName(entry.title) + '/' + entry.id, // Rail url.
isPopoverVisible: true,
popoverTitle: entry.title,
popoverDescription: entry.title
};
});
});
return railsData;
})
.publishReplay(1, this.cacheInterval)
.refCount()
.take(1)
.catchError((res: HttpErrorResponse) => throwError(res));
this.rails.set(railParams[0].railId, this.railResponse);
}
return this.rails.get(railParams[0].railId);
}
} else {
return null;
}
} else {
return null;
}
}
2 回答
Angular 6将RxJS的版本升级为具有lettable运算符的版本 . 除非安装兼容包,否则无法再使用以前的语法 .
新语法是这样的:
兼容包:here
还有一种将源代码转换为新(&IMHO crappy)语法的自动方法 .
好吧最后我发现问题并解决了,我希望它能帮助其他人,所以我在这里发帖 .
问题在于管道功能的子功能的安排 . 由于新的rxjs仅支持管道方法,因此我们使用' . '为映射函数提供的每个子函数 . 我们必须将子函数放在',' .
将此更改为..