EDIT: This question is deprecated. Please see How to set a variable from an $http call then use it in the rest of the application WITHOUT making the whole application asynchronous instead.
I have a factory
but $http
is undefined. I thought DI would define it for me.
What am I doing wrong? What fundamental misunderstanding of Angular am I guilty of here?
The extra parens ()
is causing the function to be called during the configuration phase I guess. But URL
is a property I want available right away for the whole application.
angular.module('myApp').factory('Test',['$http'],
{
URL: (function ($http) {
$http.get('http:www.myserver.com/api/thing').then(function (response) { });
})() // extra parens makes the function run right off the bat
}
);
How can I fix it?