2016-08-30 28 views

回答

0

首先,通過增加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}..."}); 
    } 
} 
相關問題