我可以在内部使用诺言HttpInterceptor吗?例如:
export class AuthInterceptor implements HttpInterceptor{
this.someService.someFunction()
.then((data)=>{
//do something with data and then
return next.handle(req);
});
}
Run Code Online (Sandbox Code Playgroud)
为什么我需要这个?因为我需要在向服务器发出请求之前获取一个令牌以添加到请求标头.
我的拦截器:
@Injectable()
export class AuthInterceptor implements HttpInterceptor{
constructor(private authService: AuthService){}
intercept(req: HttpRequest<any>, next: HttpHandler) : Observable<HttpEvent<any>>{
console.log('Intercepted!');
// return next.handle(req);
this.authService.getToken()
.then((token)=>{
console.log(token);
const reqClone = req.clone({
headers: req.headers
.set('Authorization', 'Bearer ' + token)
.append('Content-Type', 'application/json')
});
console.log(reqClone);
return next.handle(reqClone);
})
.catch((err)=>{
console.log('error in interceptor' + err);
return null;
});
}
}
Run Code Online (Sandbox Code Playgroud)
请求:
this.http.post(this.baseURL + 'hero', data)
.subscribe(
(res: …Run Code Online (Sandbox Code Playgroud) rxjs es6-promise angular angular-httpclient angular-httpclient-interceptors
我正在尝试在 xampp 中安装 mongo 驱动程序。我放入php_mongo.dllphp 的 ext 文件夹并添加extension=php_mongo.dll到文件中。php.ini现在我重新启动了 xampp,但出现此错误
Php 启动:无法加载动态库 'D:\xampp\php\ext\php_mongo.dll' - 找不到指定的模块。
请帮我解决它。我错过了任何步骤。?
angular ×1
angular-httpclient-interceptors ×1
es6-promise ×1
mongodb ×1
php ×1
rxjs ×1
xampp ×1