按需加载时,删除NgRx节点。
创始人
2024-08-22 08:00:07
0

在NgRx中,按需加载模块时,要删除已注册的NgRx节点,可以使用StoreModuleforFeature方法来注册模块,并使用StoreModuleunregister方法来注销模块。

下面是一个示例代码,展示了如何按需加载模块并删除已注册的NgRx节点:

  1. 在需要按需加载的模块中,创建一个新的NgRx模块,并使用forFeature方法注册它。
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { StoreModule } from '@ngrx/store';
import { featureReducer } from './feature.reducer';

@NgModule({
  imports: [
    CommonModule,
    StoreModule.forFeature('feature', featureReducer)
  ]
})
export class FeatureModule { }
  1. 在需要删除已注册的NgRx节点的地方,使用StoreModuleunregister方法来注销该模块。
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { StoreModule } from '@ngrx/store';
import { featureReducer } from './feature.reducer';

@NgModule({
  imports: [
    CommonModule,
    StoreModule.forFeature('feature', featureReducer)
  ]
})
export class FeatureModule {
  constructor(private storeModule: StoreModule) {
    // 注销已注册的NgRx节点
    this.storeModule.unregister('feature');
  }
}

请注意,使用unregister方法只能在需要删除节点的模块中调用。

相关内容

热门资讯

第十分钟辅助!pokemmo脚... 第十分钟辅助!pokemmo脚本辅助器下载,菠萝辅助器免费版的功能介绍,经验教程(有挂教程)1)菠萝...
7分钟辅助!wepoker透视... 7分钟辅助!wepoker透视有没有,wepoker轻量版透视,妙计教程(有挂功能)1、每一步都需要...
6分钟辅助!德普之星怎么开辅助... 6分钟辅助!德普之星怎么开辅助,wepoker脚本下载,项目教程(真实有挂)1、玩家可以在德普之星怎...
第五分钟辅助!aapoker怎... 第五分钟辅助!aapoker怎么设置提高好牌几率,如何下载wpk透视版,演示教程(有挂方针)1、aa...
第8分钟辅助!wpk安卓下载辅... 第8分钟辅助!wpk安卓下载辅助,哈糖大菠萝怎么挂,经验教程(有挂方法)哈糖大菠萝怎么挂破解侠是真的...
第三分钟辅助!hhpoker免... 第三分钟辅助!hhpoker免费辅助器,aapoker辅助软件合法吗,烘培教程(有挂神器)一、aap...
第二分钟辅助!wepoker插... 第二分钟辅助!wepoker插件功能辅助器,wepoker私人局透视插件,妙招教程(有挂细节)1、金...
六分钟辅助!wepoker透视... 六分钟辅助!wepoker透视是真的吗,wpk俱乐部辅助器,阶段教程(发现有挂)1、wepoker透...
第四分钟辅助!wepoker有... 第四分钟辅助!wepoker有没有透视方法,wepoker有机器人吗,妙计教程(有挂攻略)1、用户打...
第3分钟辅助!hh poker... 第3分钟辅助!hh poker透视器下载,德普之星透视,技法教程(有挂功能)在进入hh poker透...