0

So far I have used many times $rootScope and I had no bigger problems. Now it is a problem where i need to set $http.get to $rootScope. I always get undefined Here is ctrl

 $http.get(serviceBase + 'aaaa/aaaa/' + $stateParams.klupaID)
            .success(function (data) {
        $rootScope.klupaCreatedAt = data.created_at;
    });

Also i try make factory, but i have same problem.

$scope.currentKlupa = sveKlupeServiceFactory.get({klupa: $stateParams.klupaID});
    $scope.currentKlupa.$promise.then(function (data) {
        $rootScope.klupaCreatedAt = data.created_at;

    })

Can someone help me, how to set on $rootScope my response data. I try solution from here Why I can't set/get $rootScope? and from here Cannot get to $rootScope but without success Thnx

EDIT: here is plunker link https://plnkr.co/edit/GOq1MT7eqxBDMtkuYVvr?p=preview

Community
  • 1
  • 1
Arter
  • 2,224
  • 3
  • 29
  • 66
  • With the code provided, no real conclusions can be drawn in regards to your problem. Please provide more of your code. Maybe the entirety of your factory code and your controller code. – CraigR8806 Dec 12 '16 at 13:09
  • i edited my question, there is plunker link – Arter Dec 12 '16 at 13:35
  • I guess your issue came from your API that returns `undefined`, not from `$rootScope`... – Mistalis Dec 12 '16 at 13:46
  • if i add under $promise, console.log($rootScope.klupaCreatedAt);, i get data normaly – Arter Dec 12 '16 at 13:48
  • You want to **show in HTML** `$rootScope.klupaCreatedAt`? – Mistalis Dec 12 '16 at 13:50
  • No, take a look at my plunker. I want to get $rootScope.klupaCreatedAt to minDate for datepicker on line 76 in my controller. If i set everything inside success, datepicker don't working – Arter Dec 12 '16 at 13:52

0 Answers0