angular5.x 攔截器 switchMap


if (req.method === 'GET' && req.params.has('app_id')) {
return this.myAppListService.myListObservable.switchMap(() => {
let appId = this.myAppListService.selectedAppId;
newParams = req.params.set('app_id', appId);
const comReq = req.clone({
params: newParams,
body: newBody
});
return next.handle(comReq).do((res) => {
this.handleResponse(res);
});
});
}
 
 
if (req.method === 'POST' && req.headers.get('content-type').indexOf('application/x-www-form-urlencoded;') > -1) {
if (req.body.indexOf('app_id=')) {
return this.myAppListService.myListObservable.switchMap(() => {
let appId = this.myAppListService.selectedAppId;
newBody = req.body.replace(req.body.match(/(^|&)app_id=([^&]*)(&|$)/)[0], '');
newBody = newBody + '&app_id=' + this.myAppListService.selectedAppId;
const comReq = req.clone({
params: newParams,
body: newBody
});
return next.handle(comReq).do((res) => {
this.handleResponse(res);
});
});
}
}
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM