angular2-jwt和Ahead-of-Time编译

时间:2016-10-20 11:24:25

标签: angular auth0 angular2-aot angular2-jwt

在JiT compilcation中一切正常,但是当我尝试使用AoT进行编译时,我得到以下编译错误。谁能解释一下发生了什么?

我正在使用auth0-lock v.10.4.0和angular2-jwt v.0.1.24

错误:

Module '".../node_modules/angular2-jwt/angular2-jwt"' has no exported member 'AUTH_PROVIDERS'.

我正在使用延迟加载,所以我有一个AuthService和AUTH_PROVIDER的共享模块,如下所示:

import { AuthService } from '../common/auth.service';
import { AUTH_PROVIDERS } from 'angular2-jwt';

@NgModule({
    imports: [CommonModule],
    declarations: [],
    exports: []
})
export class SharedModule {
    static forRoot(): ModuleWithProviders {
        return {
            ngModule: SharedModule,
            providers: [
                AuthService,
                AUTH_PROVIDERS]
        };
    }
}

1 个答案:

答案 0 :(得分:1)

Found a solution here https://github.com/auth0/angular2-jwt/issues/158

Instead of AUTH_PROVIDER create your own provider like so:

export function authFactory(http: Http, options: RequestOptions) {
  return new AuthHttp(new AuthConfig({
    // Config options if you want
  }), http, options);
};

// Include this in your ngModule providers
export const authProvider = {
  provide: AuthHttp,
  deps: [Http, RequestOptions],
  useFactory: authFactory
};