AngularPrimeNG面包屑不会动态改变
创始人
2024-10-28 22:31:02
0

要动态更改面包屑,您需要使用AsyncPipe以异步方式从Observable获取路由事件。以下是一个代码示例:

在组件类中:

import { Component } from '@angular/core';
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
import { filter, map } from 'rxjs/operators';
import { MenuItem } from 'primeng/api';

@Component({
  selector: 'app-breadcrumb',
  templateUrl: './breadcrumb.component.html',
  styleUrls: ['./breadcrumb.component.css']
})
export class BreadcrumbComponent {
  items: MenuItem[];

  constructor(private router: Router, private activatedRoute: ActivatedRoute) {
    this.router.events.pipe(
      filter(event => event instanceof NavigationEnd),
      map(() => this.activatedRoute),
      map(route => {
        while (route.firstChild) route = route.firstChild;
        return route;
      }),
      filter(route => route.outlet === 'primary'),
      mergeMap(route => route.data),
      map(data => {
        if (data.title) {
          // If there is a breadcrumb override, use that instead of the title
          if(typeof data.title === 'function') {
            return data.title(this.activatedRoute.snapshot.params);
          }
          return data.title;
        } else {
          return null;
        }
      })
    ).subscribe((label: string) => {
      if (label) {
        this.items.push({label: label});
      }
    });
  }

  ngOnInit() {
    this.items = [];
  }
}

在组件模板中:


注意:确保已正确导入并安装了Primeng和rxjs模块。

相关内容

热门资讯

透视透视!wepoker透视脚... 透视透视!wepoker透视脚本苹果版,hhpoker外挂靠谱吗,必赢方法(往昔是真的有挂);原来确...
透视中牌率!hhpoker透视... 1、透视中牌率!hhpoker透视功能如何下载,sohoo poker辅助,技巧教程(果然有挂)。2...
透视游戏!wepoker脚本,... 透视游戏!wepoker脚本,pokemmo脚本手机版,新版2025教程(都是真的是有挂);亲真的是...
透视科技!wpk辅助插件,we... wpk辅助插件新手教程相关信息汇总(需添加指定Q群1067239143获取下载链接);透视科技!wp...
透视中牌率!wepoker底牌... 透视中牌率!wepoker底牌透视脚本下载,wepoker辅助器安装包定制,科技教程(本来有挂);科...
透视科技!wepoker透视底... 透视科技!wepoker透视底牌脚本,wpk透视插件,揭秘攻略(从前存在有挂)1、每一步都需要思考,...
透视安卓版!德普之星辅助器,拱... WePoker透视辅助版本解析‌,透视安卓版!德普之星辅助器,拱趴大菠萝万能辅助器,扑克教程(本然有...
透视透视!德普之星怎么作弊,w... 大家肯定在之前wepoker辅助器安装包或者wepoker辅助器安装包中玩过透视透视!德普之星怎么作...
透视插件!wpk透视表,德普之... 透视插件!wpk透视表,德普之星透视辅助插件,必备教程(先前是真的有挂)是一款可以让一直输的玩家,快...
透视总结!aapoker辅助工... 透视总结!aapoker辅助工具免费下载,wepoker私人局外卦,必胜教程(真是真的有挂),亲,有...