I'm pulling from JSONP feeds that have custom callback functions, for example:
jsonpCallbackAllStar2015({
"events": [
{
"title": "XYZ"
}
...
]
})
I'm able to do this, using the solution posted here like so:
var jsonUrl = 'http://i.cdn.turner.com/nba/nba/.element/media/2.0/teamsites/warriors/json/json-as2015.js?callback=JSON_CALLBACK' + (new Date().getTime());
$http.jsonp(jsonUrl);
window.jsonpCallbackAllStar2015 = function(data) {
$scope.events = data.events;
}
However I would now like to do this in a service so that I can load the data one time and inject it into all of my controllers. When I try this, however, I get an $injector undefined error, which I'm guessing is because the service doesn't return fast enough:
eventsFactory.$inject = ['$http'];
function eventsFactory($http) {
var jsonUrl = 'http://i.cdn.turner.com/nba/nba/.element/media/2.0/teamsites/warriors/json/json-as2015.js?callback=JSON_CALLBACK' + (new Date().getTime());
$http.jsonp(jsonUrl);
window.jsonpCallbackAllStar2015 = function(data) {
return data.events;
}
}
Is there anyway to fix this or will I have to repeat the jsonp request in each controller? Here is a fiddle.