简体   繁体   English

将数据从登录路由组件传递到导航菜单组件

[英]Passing data from login routed component to Nav-menu component

I need some help with my angular app , I have a .net core application using Angular 6 as the front end. 我需要一些有关我的angular应用程序的帮助,我有一个使用Angular 6作为前端的.net核心应用程序。 Now in Angular app there is an APP Module and there a feature Module. 现在,在Angular应用中有一个APP模块和一个功能模块。 App module contains the nav-bar menu. 应用程序模块包含导航栏菜单。 And Feature module has a home Component and some other components. 而Feature模块具有一个Home Component和一些其他组件。 I also have a separate Login application ( which is in .net) . 我也有一个单独的Login应用程序(位于.net中)。

Now Login app is used for authentication and on successful authentication Angular app home Component gets called through router-outlet. 现在,登录应用程序用于身份验证,并且在成功进行身份验证后,将通过路由器出口调用Angular应用程序主组件。 this is my app component 这是我的应用程序组件

Now how do I pass data from home component which is routed through router-outlet to nav-bar 现在,我如何将数据从本地组件传递出去,该组件通过路由器出口路由到导航栏

You can achieve it via either of the following ways - 1. Have a service which will maintain the shared data. 您可以通过以下两种方法之一来实现它:1.拥有一项将维护共享数据的服务。 This data will be updated by HomeComponent and watched by your NavMenuComponent. 此数据将由HomeComponent更新,并由NavMenuComponent监视。 This data could be in the form of observable. 该数据可以是可观察的形式。 2. Use a store like ngrx or ngxs to maintain your state. 2.使用ngrx或ngxs之类的商店来维护您的状态。 As ngrx or ngxs are redux based and reactive, it will be super easy to achieve the thing that you would like to achieve. 由于ngrx或ngxs是基于redux的,并且是反应性的,因此实现您想要实现的目标将非常容易。 Although it is a bit learning curve. 虽然有点学习曲线。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM