Angular2 刷新路由器插座 [英] Angular2 refresh router-outlet

查看:39
本文介绍了Angular2 刷新路由器插座的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆