问题描述
我使用ng update
将我的应用程序从Angular 7升级到了Angular 8.当我通过ng serve
运行它时,控制台上从ngrx
打印了一个警告:
I upgraded my app from Angular 7 to Angular 8 using ng update
. When I run it via ng serve
, There's a warning printed in my console from ngrx
:
@ngrx/store: runtime checks are currently opt-in but will be the default in the next major version with the possibility to opt-out, see https://ngrx.io/guide/migration/v8 for more information.
提供的链接上的文档讨论了不推荐使用的ngrx-store-freeze
.但是,我的应用程序不使用ngrx-store-freeze
,我也不知道什么是运行时检查".我需要在代码中进行哪些更改以解决此警告的来源?
The documentation at the provided link talks about ngrx-store-freeze
being deprecated. However, my application does not use ngrx-store-freeze
, and I have no idea what a "runtime check" is. What do I need to change in my code to address the source of this warning?
推荐答案
此警告即将到来是因为NGRX< 8,要使商店不可变,我们需要使用ngrx-store-freeze库.在NGRX 8中,您可以选择不使用ngrx-store-freeze而使存储不可变(因为它现在在NGRX 8中是内置的).如果通过在StoreModule.forRoot
中指定runtimeChecks
属性来选择店内不变性,则该警告将消失:
This warning is coming because in NGRX < 8, to make store immutable, we need to use ngrx-store-freeze library. In NGRX 8, you can opt-in to make store immutable without ngrx-store-freeze [as it is in build now in NGRX 8]. This warning will go away if you opt in-store immutability by specifying runtimeChecks
property in StoreModule.forRoot
like this:
StoreModule.forRoot(rootReducer, {
runtimeChecks: {
strictStateImmutability: true,
strictActionImmutability: true
}
})
示例:
@NgModule({
imports: [
CommonModule,
StoreModule.forRoot(rootReducer, {
runtimeChecks: {
strictStateImmutability: true,
strictActionImmutability: true
}
}),
]
})
export class AppModule {}
希望这会有所帮助.
这篇关于来自ngrx的有关运行时检查的警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!