0

I have main controller:

.controller('mainCtrl', ['$scope', '$rootScope', 'Data', '$http', '$log', '$filter', '$q', '$timeout', function($scope, $rootScope, Data, $http, $log, $filter, $q, $timeout){

            Data.get('customers').then(function(data){
                $scope.customers = data.data;
                $rootScope.language = data.data[0].language;
            });

            $rootScope.word_pub_curr_lang = 'word_pub_' + $rootScope.language;
            console.log('from maincrtl', $rootScope.word_pub_curr_lang);

    }]);

The problem is that I can't receive $rootScope.word_pub_curr_lang or $rootScope.language - are always undefined.

georgeawg
  • 48,608
  • 13
  • 72
  • 95
andrzej
  • 495
  • 1
  • 7
  • 18

1 Answers1

3

It is getting undefined because, it gets printed before you actually get the value from the request, place them inside,

controller('mainCtrl', ['$scope', '$rootScope', 'Data', '$http', '$log', '$filter', '$q', '$timeout', function($scope, $rootScope, Data, $http, $log, $filter, $q, $timeout){
            Data.get('customers').then(function(data){
                $scope.customers = data.data;
                $rootScope.language = data.data[0].language;
                $rootScope.word_pub_curr_lang = 'word_pub_' + $rootScope.language;
               console.log('from maincrtl', $rootScope.word_pub_curr_lang);
            });

    }]);
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396