Angular2 refresh router-outlet

自古美人都是妖i 提交于 2019-12-25 09:19:47

问题


I'm working on a CRM and I have a select box in the header which allows the user to change the current user, In addition, the main content is inside the router-outlet.

When the user select another user I want to refresh the page but only the router-outlet so the info will be for the new user

I saw that other CRMs just redirect the user to the dashboard / index page, but I want to keep the user on the same page.


回答1:


You should have a function in a service

import {Subject} from 'rxjs/Subject';

onUserChange= new Subject<void>();

userChange(): void {
    this.http.post('')
        .map()
        .subscribe((data: UserChangeResponse) => {
             this.onUserChange.next();
        })
}

And In component you can use it in ngOnInit

serviceReference.onUserChange.subscribe(() => {

     // use can call get users method or anything

});


来源:https://stackoverflow.com/questions/44406679/angular2-refresh-router-outlet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!