angular2-jwt 和提前编译
angular2-jwt and Ahead-of-Time Compilation
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
};
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
};