问题描述
我正在尝试在我的app.module文件中设置一个配置设置,以便根据我是否在生产中而有所不同.
I am trying to set a config setting in my app.module file so that it's different depending on if I'm in production or not.
我的 environment.ts
文件具有
export const environment = {
production: false
};
我的 environment.prod.ts
文件具有
export const environment = {
production: true
};
在我的 app.module.ts
文件中,我正在尝试类似的事情
In my app.module.ts
file I am attempting something like this
imports: [
BrowserModule,
AppRoutingModule,
LoggerModule.forRoot({
level: (environment.production ? NgxLoggerLevel.OFF : NgxLoggerLevel.DEBUG)
}),
...
当我在任何地方执行 console.log(environment.production)
时,它告诉我该值是 false
,就像我在开发环境中应该的那样.
When I do console.log(environment.production)
anywhere it tells me this value is false
as it should be while I am in the development environment.
我的问题是,它似乎在我的app.module文件中充当 true
.在这种情况下,我试图将我的日志语句设置为在生产环境中被禁用,但是在开发和生产中它们也会被禁用.(如果我翻转条件语句,那么它们将同时在开发和生产中启用).因此,就好像它正在读取environment.production时应该是真实的一样.
My problem is that it seems to be acting as true
in my app.module file. I'm trying to set my log statements to be disabled on the production environment in this case, but they are also getting disabled in development and production. (If I flip my conditional statement then they get enabled in both dev and production). So it's as if it's reading environment.production to be true when it shouldn't be.
不能在app.module中像这样使用environment.production变量吗?还是我在这里遗漏了其他内容?
Can the environment.production variable not be used like this in app.module or am I missing something else here?
推荐答案
我直接在app.module.ts顶部直接导入了生产版本
I was directly importing the production version directly at the top of app.module.ts
import { environment } from 'src/environments/environment.prod';
代替
import { environment } from 'src/environments/environment';
这篇关于在app.module.ts中,environment.production变量始终为true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!