如何在 NgModule 装饰器中使用 isDevMode() ?目前说“AppModule 的 NgModule.imports 中位置 X 的值不是参考”

问题描述 投票:0回答:1
我只是想知道如何在我的

boolean

 装饰器中使用返回 
NgModule
 的函数?我的项目是 Angular 16。

这是我的

app.module.ts

:

import { NgModule, isDevMode } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { AppComponent } from './app.component'; import { StoreModule } from '@ngrx/store'; import { reducers, metaReducers } from './store'; import { StoreDevtoolsModule } from '@ngrx/store-devtools'; @NgModule({ declarations: [ AppComponent, ], imports: [ BrowserModule, StoreModule.forRoot(reducers, { metaReducers }), isDevMode() ? StoreDevtoolsModule.instrument() : [], // <- This is what makes my code to throw error! ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }
这是我遇到的错误:

Value at position 2 in the NgModule.imports of AppModule is not a reference Value could not be determined statically.(-991010) app.module.ts(15, 5): Unable to evaluate this expression statically. app.module.ts(15, 5): A value for 'isDevMode' cannot be determined statically, as it is an external declaration. (alias) isDevMode(): boolean import isDevMode Returns whether Angular is in development mode. By default, this is true, unless enableProdMode is invoked prior to calling this method or the application is built using the Angular CLI with the optimization option.
    
angular ngrx ngrx-store
1个回答
0
投票
您可以按照此方法从生产版本中排除开发工具 -

https://ngrx.io/guide/store-devtools/recipes/exclude

© www.soinside.com 2019 - 2024. All rights reserved.