Currently, I am exploring AngularJS to develop my very first application. My main goal is to ensure that the run function is executed before any controller.
Here's a snippet of my run function:
.run(function ($rootScope, authentification)
{
teamsFactory.sendAuthent().then(function(response)
{
$rootScope.authentdata = response.data;
});
})
Within my service where authentication takes place:
teams.sendAuthent = function(DeviceID) {
return $http({
method: "POST",
url: "http://myserver.com/authentification",
headers: {'X-SocialAPI-Service-Name': 'auth'}
})
.then(function(aResponse)
{
var deferred = $q.defer();
deferred.resolve({ data: aResponse.data });
return deferred.promise;
});
}
Furthermore, here is the controller where I utilize the rootScope data:
.controller('home', function($rootScope, $scope, $http)
{
alert($rootScope.authentdata.token);
})
Unfortunately, I'm encountering an issue where it states that `autehndata` is undefined. It seems like the controller is being executed before the run function. How can I resolve this problem?