在我的应用程序从角5迁移到6之后,rxjs引起了各种各样的问题。在迁移过程中和移除之后,我使用了rxjs-紧凑,因为它会导致更大的内存利用率。我被留下了这样的错误。
./node_modules/rxjs-compat/_esm5/add/operator/publishReplay.js模块构建中的错误失败:错误: ENOENT:没有这样的文件或目录,打开'/home/training/Desktop/vishnu/TemplateAppv6/node_modules/rxjs-compat/_esm5/add/operator/publishReplay.js‘
我尝试过从rxjs和rxjs/操作符导入publishReplay。
从‘rxjs/操作符’导入{ filter,map,catchError,publishReplay };
但是问题仍然存在,像publishReplay这样的catchError还有什么变化吗?
任何帮助都将不胜感激。
这是完整的代码
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;
}
}
发布于 2018-09-26 04:18:47
好的,我终于发现了这个问题并解决了,我希望它能帮助其他一些人,所以我在这里张贴它。
问题是管道功能子功能的安排。由于新的rxjs只支持管道方法,所以我们给出的每个子函数都是使用“.”映射函数的。我们必须把子函数和“,”放在一起。
.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);
}
把这个换成..。
.pipe(map((response: GetRailsResponse) => {
return response;
}),
publishReplay(1, this.cacheInterval),
refCount(),
take(1),
catchError((res: HttpErrorResponse)=> {
return throwError(res)
})
);
this.rails.set(JSON.stringify(requestBody), this.railsRes);
}
发布于 2018-09-25 07:25:37
Range6升级了RxJS的版本,使之具有可供选择的运算符。除非安装兼容性包,否则不能再使用以前使用的语法。
新语法如下所示:
import { map } from 'rxjs/operators';
import { Observable, of } from 'rxjs';
let squares: Observable<number> = of(1, 2).pipe(
map(m => m * m)
);兼容性包:这里
还有一种自动的方法可以将源代码转换为新的(& IMHO )糟糕的语法。
https://stackoverflow.com/questions/52492541
复制相似问题