如何在Angular 4.3.5中拦截对组件html模板的请求

时间:2017-09-21 13:08:15

标签: angular angular4-httpclient

我需要拦截对html组件模板的请求。角度版本为4.3.5

我尝试使用角度httpClient手册(https://angular.io/guide/http)中描述的实现拦截器来实现它

interceptor.service.js

import {Injectable} from '@angular/core';
import {HttpEvent, HttpInterceptor, HttpHandler, HttpRequest} from '@angular/common/http';

@Injectable()
export class AuthInterceptor implements HttpInterceptor {
  constructor(private auth: AuthService) {}

  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    // Get the auth header from the service.
    const authHeader = this.auth.getAuthorizationHeader();
    // Clone the request to add the new header.
    const authReq = req.clone({headers: req.headers.set('Authorization', authHeader)});
    // Pass on the cloned request instead of the original request.
    return next.handle(authReq);
  }
}

app.module.js

import {NgModule} from '@angular/core';
import {HTTP_INTERCEPTORS} from '@angular/common/http';

@NgModule({
  providers: [{
    provide: HTTP_INTERCEPTORS,
    useClass: NoopInterceptor,
    multi: true,
  }],
})
export class AppModule {}

但是它拦截了我自己编写的服务和组件的http请求,但没有拦截对由angular进行的html模板的请求。

还有其他办法吗?

1 个答案:

答案 0 :(得分:1)

如果您可以访问if xbmc.getCondVisibility('system.platform.android'): import subprocess df = subprocess.Popen(['df', '/storage/emulated/legacy'], stdout=subprocess.PIPE) output = df.communicate()[0] info = output.split('\n')[1].split() size = float(info[1].replace('G', '').replace('M', '')) * 1000000000.0 size = size - (size % float(info[-1])) available = float(info[3].replace('G', '').replace('M', '')) * 1000000000.0 available = available - (available % float(info[-1])) return int(round(available)), int(round(size)) ,请尝试覆盖@angular/compiler

<强> main.ts

ResourceLoader

<强> Plunker Example