0

I have defined rootscope parameters in .run method as follows. `

app.run(function($rootScope,$http) {
  $http.get('user/getBaseinfo').then(function success(response) {
    $rootScope.userRole = response.data.userRole;
    $rootScope.userRoleId = response.data.userRoleId;
 });
})` 

as am injecting some parameters in rootscope. so when i print any variable in controller it gives undefined at first but if i am doing it on next call it gives the values. I did not understand the behavior. Can anybody help. my controller

app.controller('staffAttendanceController',['$scope','$http', '$rootScope',  function($scope, $http, $rootScope) {
 $scope.attendance_staff = {}; 

 console.log(userRole); //Undefined

 //Load data at first
 $http.get(API_URL + 'staffattend/listAll').then(function success(response) {
    $scope.attendance_staff = response.data.data;
    console.log(userRole); //Admin
 });
}]);

I want variable to be appear at very first line of controller which are declared in rootScope.

Vishal B
  • 653
  • 2
  • 12
  • 31

0 Answers0