简体   繁体   English

如何使用AngularJS在2个应用之间共享变量

[英]How to share variable between 2 app with AngularJS

I have an angularjs app with 2 main folder. 我有一个带有2个主文件夹的angularjs应用。 Webapp -> admin / user. Webapp->管理员/用户。

Each one contain html and js files in order to display the webapp. 每个都包含html和js文件,以便显示webapp。 All the app. 所有的应用程序。 is based on REST principal, so when I get the data from the backend (springMVC/Hibernate/JPA), it's a JSON file. 基于REST主体,因此当我从后端(springMVC / Hibernate / JPA)获取数据时,它是一个JSON文件。

On the admin side, I have a user.js file with a controller : 在管理方面,我有一个带控制器的user.js文件:

Service.userRead($routeParams.id).then(function(data) {
     if (data.status == SUCCESS) {
           $scope.userIn = data.user;
           var color = $scope.userIn.bannerColor;

     } else {
           logger.warn('userRead: ' + JSON.stringify(data));    
           $scope.redirectTo('/users');
     }
}

On the user side, when the client is on the webapp (not connected to the admin side) I want to obtain the background-color previously stored for a particular user in the database. 在用户端,当客户端在Webapp上(未连接到管理端)时,我想获取先前为特定用户存储在数据库中的背景色。 these hex code is for styling the header. 这些十六进制代码用于标头样式。

the question is : how can I retrieve data from the controller user.js and past the variable color to the header controller located in the other folder (HeaderController in user side) ? 问题是:如何从控制器user.js检索数据并将变量color传递到另一个文件夹(用户端的HeaderController)中的标头控制器?

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

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