I need to change the title of a page not included in the sidebar menu when using ng-admin2. Primarily, when dynamically editing an object and really anytime doing anything with dynamic routing.
Asked
Active
Viewed 177 times
1 Answers
0
First, import AppState
by adding import {AppState} from '../app.state';
Second, make sure you reference it in your constructor:
constructor(private _state: AppState) {}
Third, inside of ngOnInit()
or in a subsequent function after the constructor, call the notifyDataChanged
function inside this._state
, like this:
this._state.notifyDataChanged('menu.activeLink', {title:"Edit User ${username}..."});
Also, to exclude a navigational item from the side menu, just remove the menu:{title:''}
inside of data
in your pages.routes.ts
file.
I'm sure there's a way to tweak the overall component to be more complete, but in my simple implementation, this worked fine.
So completed code should look something like this:
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}..."});
}
}

jamesbar2
- 614
- 1
- 9
- 20