【发布时间】:2018-03-09 08:15:12
【问题描述】:
我目前正在制作一个依赖于主机环境的自定义角度库。理想情况下,我只想在我的模块的forRoot 方法中传递几个环境变量,以便服务使用,具体取决于使用它的应用程序以及它们所处的环境。但是在使用 angular- 编译时出现错误cli,然后将变量从我的environment.ts 传入app.module.ts。
错误中的错误:静态解析符号值时遇到错误。不支持函数调用。考虑将函数或 lambda 替换为对导出函数的引用(原始 .ts 文件中的位置 19:24),在 /Users/griffin/DCP/customer-dashboard/src/environments/environment.ts 中解析符号环境,解析/Users/griffin/DCP/customer-dashboard/src/app/app.module.ts中的符号AppModule,解析/Users/griffin/DCP/customer-中的符号AppModule
自定义模块的索引当前设置如下:
@NgModule({
declarations: [],
exports: [],
providers: [
AuthService
],
imports: [
HttpModule,
BrowserModule
]
})
export class CommonAuthModule {
static forRoot(config: AuthServiceConfig): ModuleWithProviders {
return {
ngModule: CommonAuthModule,
providers: [
{provide: AuthServiceConfig, useValue: config }
]
};
}
在一个 Angular 项目中我是这样导入的:
import { CommonAuthModule } from '@dcp/common-auth';
import { environment } from '../environments/environment';
@NgModule({
declarations: [
AppComponent
],
imports: [
CommonAuthModule.forRoot(environment.authConfig) // Import here
...
})
export class AppModule { }
environment.authConfig 是一个简单的对象
authConfig: {
authenticationUrl: 'https://streamworks.auth0.com/login?client=',
clientId: 'f98h3f3fdsousfoihohfjwe0',
auth0Domain: 'streamworks.auth0.com'
}
而 AuthServiceConfig 是一个简单的类
export class AuthServiceConfig {
clientId: string = ''
auth0Domain: string = '';
authenticationUrl: string = '';
}
我看到过类似的问题,例如 this 帖子。这与 AoT 编译有关吗?我尝试绕过 AoT 来构建项目,但仍然遇到同样的错误。
【问题讨论】:
标签: angular typescript angular-ngmodel