在JiT编译中一切都很好,但是当我尝试使用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]
};
}
}
找到解决方案了https://github.com/auth0/angular2-jwt/issues/158
代替AUTH_PROVIDER创建你自己的提供商,像这样:
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
};