0
當使用ng-admin2時,我需要更改未包含在側邊欄菜單中的頁面的標題。主要是在動態編輯對象時,並且實際上可以隨時用動態路由進行任何操作。ng-admin2:設置不包含在菜單中的頁面的標題
當使用ng-admin2時,我需要更改未包含在側邊欄菜單中的頁面的標題。主要是在動態編輯對象時,並且實際上可以隨時用動態路由進行任何操作。ng-admin2:設置不包含在菜單中的頁面的標題
首先,通過增加import {AppState} from '../app.state';
其次進口AppState
,請確保您引用它在構造函數:
constructor(private _state: AppState) {}
三,ngOnInit()
內或在構造之後的後續功能,調用notifyDataChanged
功能this._state
,如下所示:
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}..."});
}
}