代码之家  ›  专栏  ›  技术社区  ›  saimonsez

角度延迟路径和可选矩阵参数

  •  0
  • saimonsez  · 技术社区  · 7 年前

    角度6

    我正在使用一个全局可选的矩阵参数来动态切换语言和ngx translate:my app/some component;lang=it

    在我引入所有应用程序模块的延迟加载之前,这段代码曾经起作用

    应用组件.ts

    this.router.events.subscribe((event: Event) => {
      if (event instanceof RoutesRecognized) {
        const params = event.state.root.firstChild.params;
        const lang = params['lang'];
        if (lang) {
          this.languageService.changeLanguage(lang);
        }
      }
    });
    

    对于延迟加载,参数变量为空。我不知道如何恢复所需的功能。

    这也不起作用(空):

    this.activatedRoute.params.subscribe(params => console.log(params));
    
    this.activatedRoute.url.subscribe(segments => {
      segments.forEach(segment => console.log(segment.parameterMap.keys));
    });
    

    我没有主意,需要一些帮助。

    1 回复  |  直到 7 年前
        1
  •  0
  •   saimonsez    7 年前

    经过更多的研究,我找到了一个解决办法。

    不过看起来很难看

    this.router.events.pipe(
      filter(event => event instanceof RoutesRecognized)
    ).subscribe((event: RoutesRecognized) => {
      event.state.root.children.forEach(child => {
        child.children.forEach(c => {
          const params = c.params;
          // do stuff
        });
      });
    });
    
    推荐文章