【问题标题】:angular2-jwt and Ahead-of-Time Compilationangular2-jwt 和提前编译
【发布时间】:2017-03-02 08:59:12
【问题描述】:

在 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]
        };
    }
}

【问题讨论】:

    标签: angular auth0 angular2-aot angular2-jwt


    【解决方案1】:

    在这里找到了解决方案 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
    };
    

    【讨论】:

      猜你喜欢
      • 2017-03-10
      • 2017-01-22
      • 2017-01-12
      • 1970-01-01
      • 1970-01-01
      • 2016-07-06
      • 1970-01-01
      • 1970-01-01
      • 2017-08-06
      相关资源
      最近更新 更多