angular – RxJS 6 switchMap使用不推荐使用的符号
发布时间:2020-12-17 08:46:55 所属栏目:安全 来源:网络整理
导读:我已经从Angular 5更新到Angular 6.现在我正在尝试更新我的代码以使其与RxJS 6兼容. .pipe( map(job = job[0]),switchMap((job) = { return job ? this.bookingService.findByID(job.property.id) : Observable.empty(); },(job: Job,bookings: Booking[]) =
我已经从Angular 5更新到Angular 6.现在我正在尝试更新我的代码以使其与RxJS 6兼容.
.pipe( map(job => job[0]),switchMap((job) => { return job ? this.bookingService.findByID(job.property.id) : Observable.empty(); },(job: Job,bookings: Booking[]) => { this.mark_jobs_unavailable(job,bookings); return job; }) ) 我在使用使用了Deprecated Symbol的switchMap时收到警告. 这些是我的导入:从’rxjs /运算符’导入{map,switchMap}; 在v6中有没有其他方法可以使用switchMap?此外,如果我不更改我的代码rxjs-compat应该使我现有的代码工作(我已安装)但我得到以下错误相同的代码,但在RxJS 5样式: .map(job => job[0]) .switchMap((job) => { return job ? this.bookingService.findByID(job.property.id) : Observable.empty(); },bookings); return job; }) 错误:预期1个参数但得到2.
作为switchMap的第二个参数给出的resultSelector函数是
deprecated.您需要删除它并使用map运算符实现目标.
这里最棘手的部分是决定放置地图运算符的位置.实际上地图运算符进入了作为switchMap参数提供的函数体内部. 没有结果选择器功能的代码将类似于以下内容: .pipe( map(job => job[0]),switchMap((job) => { return (job ? this.bookingService.findByID(job.property.id) : Observable.empty()).pipe( // This is the mapping function provided as the alternative to the deprecated result selector function // This should be placed inside the body of the function which is the 1st (and only one) argument of switchMap map((bookings: Booking[])=>{ this.mark_jobs_unavailable(job,bookings); return job; }) ); } ) ) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |