0

I have an angularjs app with 2 main folder. Webapp -> admin / user.

Each one contain html and js files in order to display the 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.

On the admin side, I have a user.js file with a controller :

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. 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) ?

1 Answer 1

0

Refer AngularJS Modules/Scope Sharing

Sign up to request clarification or add additional context in comments.

7 Comments

thanks @Gayathri for your answer. but when I made it, on the other controller for console.log($rootScope.variable) I got "undefined".
Are both the controllers available in same module? Perhaps some more portion of code can help me identify why
Try module.controller('MyController', ['$scope', '$rootScope',function($scope, $rootScope) { ... }]);
controllers are available in same module. Declared separately in two index.js as : var myApp = angular.module('myApp', ['ngAnimate', 'ngRoute', 'ngSanitize', 'angular-growl', 'angulartics', 'angulartics.google.analytics', 'myAppControllers']);
and then : var controllers = angular.module('myAppControllers', []); in order to simplify the declaration of a controller in user.js controller for example
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.