Http “逃避”;“使用工厂”;在Angular2中过度引用提供程序时
我的问题与@angular/http的http模块的过度使用有关。我正在使用下面的代码拦截每个Http请求:Http “逃避”;“使用工厂”;在Angular2中过度引用提供程序时,http,angular,factory,provider,Http,Angular,Factory,Provider,我的问题与@angular/http的http模块的过度使用有关。我正在使用下面的代码拦截每个Http请求: export let fakeBackendProvider = { // intercepts every single Http call provide: Http, useFactory: (backend: MockBackend, options: BaseRequestOptions) => { backend.connections.subscr
export let fakeBackendProvider = {
// intercepts every single Http call
provide: Http,
useFactory: (backend: MockBackend, options: BaseRequestOptions) => {
backend.connections.subscribe((connection) => {
// here I treat requests for their urls
if(connection.endsWith('/example/') {
// ...
}
// here I'd like to CONTINUE the normal execution as it is,
// as if THIS call had never entered in "useFactory" peace of code
if(connection.endsWith('/example.noprovider/') {
// GO ON
}
})
return new Http(backend, options)
},
deps: [MockBackend, BaseRequestOptions]
}
我需要什么
- 通过HTTP请求从JSON文件获取数据
最好知道问题的确切原因是什么?:-)是的,很抱歉。问题是,我正在发送一个http请求,以获取代码中的json文件。并且在通过useFactory代码块时找不到如何实现该操作。我想继续现在的操作,有点“下一步”的观察。thnx@user1713747请给出一个问题来解释这个问题。我使用了这个Http拦截器示例。也许有帮助。
if(url === 'useinterceptor) {
// USE INTERCEPTOR
}
if(url === 'notuseinterceptor') {
// USE HTTP GET OPERATION AS IT IS
}