Angular2 刷新路由器插座 [英] Angular2 refresh router-outlet
问题描述
我正在开发 CRM,我在标题中有一个选择框,允许用户更改当前用户,另外,主要内容在router-outlet里面.
当用户选择另一个用户时,我想刷新页面但只刷新路由器插座,以便新用户的信息
我看到其他 CRM 只是将用户重定向到仪表板/索引页面,但我想让用户保持在同一页面上.
你应该在服务中有一个函数
import {Subject} from 'rxjs/Subject';onUserChange= new Subject();用户更改():无效{this.http.post('').地图().subscribe((data: UserChangeResponse) => {this.onUserChange.next();})}
<块引用>
在组件中你可以在 ngOnInit 中使用它
serviceReference.onUserChange.subscribe(() => {//use 可以调用 get users 方法或任何东西});
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.
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
});
这篇关于Angular2 刷新路由器插座的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!