我已将angular-cli
从beta.21
更新为最新版本,但在编译项目时遇到错误:Calling function 'ApiAuthModule', function calls are not supported
我想我确实将所有代码都移到了导出的函数中。它可能是什么?
这是我的错误:
ERROR in Error遇到静态解析符号值。调用函数' ApiAuthModule',不支持函数调用。考虑使用对导出函数的引用替换函数或lambda,在C:/strony/www/libsNg/ApiAuth/src/app/app.module.ts中解析符号AppModule,在C:/ strony / www /中解析符号AppModule libsNg / ApiAuth / SRC /应用程序/ app.module.ts
这是我的api-auth.module.ts
:
import {NgModule} from "@angular/core";
import {CommonModule} from "@angular/common";
import {ApiModule} from "./api/api.module";
import {ApiService} from "./api/api.service";
import {ApiConfig, ApiConfigModel} from "./api/api-config";
import {ResponseHandlerService} from "./response-handler/default/response-handler.service";
import {AuthModule} from "./auth/auth.module";
import {AuthService} from "./auth/auth.service";
import {AuthConfig, AuthHttp} from "angular2-jwt";
import {Http, HttpModule, RequestOptions} from "@angular/http";
@NgModule({
imports: [
CommonModule,
HttpModule,
ApiModule,
AuthModule
],
declarations: []
})
export class ApiAuthModule {
static config: ApiConfigModel;
static forRoot(config: ApiConfigModel) {
// static forRoot(config: ApiConfigModel): ModuleWithProviders {
let responseHandlerClass = config.responseHandlerService || ResponseHandlerService;
this.config = config;
return {
ngModule: ApiAuthModule,
providers: [
ApiService,
AuthService,
{
provide: AuthHttp,
useFactory: authHttpServiceFactory,
deps: [Http, RequestOptions]
},
// AUTH_PROVIDERS,
// provideAuth({
// // headerName: YOUR_HEADER_NAME,
// // headerPrefix: YOUR_HEADER_PREFIX,
// tokenName: localStorageTokenId,
// tokenGetter: tokenGetterFunc(localStorageTokenId),
// // globalHeaders: [{'Content-Type': 'application/json'}],
// noJwtError: true,
// // noTokenScheme: true
// }),
{
provide: ApiConfig,
useFactory: ApiConfigFactory
},
{
provide: ResponseHandlerService,
useClass: responseHandlerClass
}
]
};
}
}
export function ApiConfigFactory() {
// console.log(ApiAuthModule.config);
return new ApiConfig(ApiAuthModule.config);
}
// export function tokenGetterFunc(localStorageTokenId) {
// return localStorage.getItem(localStorageTokenId);
// }
export function authHttpServiceFactory(http: Http, options: RequestOptions) {
let localStorageTokenId = ApiAuthModule.config.localStorageTokenId || 'id_token';
return new AuthHttp(new AuthConfig({
tokenName: localStorageTokenId,
tokenGetter: (() => localStorage.getItem(localStorageTokenId)),
// tokenName: 'token',
// tokenGetter: (() => sessionStorage.getItem('token')),
}), http, options);
}
app.module.ts
:
import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {HttpModule} from '@angular/http';
import {AppComponent} from './app.component';
import {ApiAuthModule} from "./api-auth/api-auth.module";
import {AlertyModule} from "lukana-alerty";
import {NgbModule} from "@ng-bootstrap/ng-bootstrap";
import {ResponseHandlerAlertyService} from "./api-auth/response-handler/alerty/response-handler-status.service";
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
ApiAuthModule.forRoot({
baseUrl: 'http://www.system.local/api/',
authUrl: 'auth/login/',
responseJsonTokenId: 'token',
responseHandlerService: ResponseHandlerAlertyService//ResponseHandlerStatusService
}),
NgbModule.forRoot(),
AlertyModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {
}