angularjs - get data from angular.module config to the corresponding controller -


i have following configuration, have config url called using $http.get method , data stored in variable "alpha". how access variable controller. tried inject $rootscopeprovider config , tried set $rootscope.pqr = alpha. gives error. how do it?

angular.module('thisapp', [somedependencies]).config( function($stateprovider, $urlrouteprovider) {     $http.get('url').then(function(response) {         var alpha = response.data; // need access data in controller     )}; }).directive('pqrtitle', function () {     return {         restrict: 'a',         controller: function($scope, $rootscope) {          // need access alpha here     }); }); 

how do this?

if using ui-router-extras, can use $futurestateprovider this, use $rootscope , access in controller

angular.module('thisapp', [somedependencies]) .config( function($futurestateprovider, $stateprovider, $urlrouteprovider) {      $futurestateprovider.addresolve(['$http', '$rootscope', function($http, $rootscope) {         $http.get('url').then(function(response) {             $rootscope.alpha = response.data;         )};     }]); }) 

1) in controller, should inject rootscope , access variable. read understand $futurestateprovider in ui-router extras

2) if not want use rootscope, make service , inject teh $futurestateprovider.addresolve, set variable in service. after can variable value through getter function

hope helps


Comments