有条件的提供程序连接

时间:2019-04-01 10:09:25

标签: angular

我有点喜欢Angular。我最近加入了有条件地连接Auth Interceptor的项目,具体取决于环境。它在JIT编译上效果很好,但是由于我尝试在AOT编译上移动项目,因此授权崩溃并显示401错误。似乎拦截器不起作用

实际上我不知道在哪里挖,因为environment.isSbrf返回false

/*imports here*/

let providers: Array<any> = [
  { provide: AuthService, useClass: AgentAuthService },
  { provide: WorkflowStateService, useClass: AgentWorkflowStateService },
  /*other providers here*/
];

console.log(environment);

if (!environment.isSbrf) {
  providers.unshift({ provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true });
  providers.unshift({ provide: HTTP_INTERCEPTORS, useClass: AuthAgentIdInterceptor, multi: true });
}

@NgModule({
  imports: [
    CommonModule,
    HttpClientModule,
    ServicesModule,
    FormsModule,
    ReactiveFormsModule,
    AuthModule,
    /*other modules here*/
  ],
  providers: providers,
  declarations: [
    /*components here*/
  ]
})
export class AgentModule { }

我希望我会像使用JIT编译一样从Auth拦截器中的本地存储中接收令牌,但不适用于AOT。

1 个答案:

答案 0 :(得分:0)

我认为它已解决,请确保您具有最新版本的angular,请参阅github中的问题 https://github.com/angular/angular/issues/18293