ng-admin2:设置菜单中不包含的页面的标题



使用ng-admin2时,我需要更改未包含在侧边栏菜单中的页面标题。首先,当动态编辑对象时,以及在任何时候使用动态路由做任何事情时。

首先,通过添加import {AppState} from '../app.state';

导入AppState第二,确保在构造函数中引用了它:
  constructor(private _state: AppState) {}

第三,在ngOnInit()内部或构造函数之后的后续函数中,调用this._state内部的notifyDataChanged函数,如下所示:

  this._state.notifyDataChanged('menu.activeLink', {title:"Edit User ${username}..."});

另外,要从侧边菜单中排除导航项,只需在pages.routes.ts文件中删除data中的menu:{title:''}

我确信有一种方法可以调整整个组件使其更完整,但在我的简单实现中,这工作得很好。

所以完整的代码应该是这样的:
import {Component, OnInit} from '@angular/core';
import {AppState} from '../app.state';
@Component({
  selector: 'edit-user',
  template: require('./edit-user.html')
})
export class EditUserComponent implements OnInit{
  public username : string;
  constructor(private _state: AppState) {
     //if you call notifyDataChanged here, it won't take since it's called again
  }
  ngOnInit() {
    this._state.notifyDataChanged('menu.activeLink', {title:"Edit User ${username}..."});
  }
}

最新更新