This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Loading scripts dynamically and resolving view using promisses does break changing route #2894
Closed
Description
View 'switch' does not happen. On mouse click it happens, although template displays twice (one is not compiled).
$routeProvider.when('/pricing', {
templateUrl:'partials/pricing.html',
controller: 'PricesCtrl',
resolve: {
'pricings': window.XYZ.utils.resolveJSONP(
'http://someaddress/latest/pricing.js', 'CALLBACK_PRICINGS')
});
...
window.XYZ.utils.resolveJSONP = function(url, callbackName){
return function($resource, $q, $timeout){
var deferred = $q.defer();
window[callbackName] = function(data){
// this gets printed, but view does not switch
console.debug('resolved: '+url);
deferred.resolve(data);
};
(function() {
var script = document.createElement('script');
script.type = 'text/javascript'; script.async = true;
script.src = url;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(script, s);
})();
return deferred.promise;
};
};
Is this because $q or loading templates collides with custom script loading? How to avoid this problem? I can not do regulat JSONP with variable callback name, since the point of what I am doing is to load a static resource.
Thanks anyone for helping.
Metadata
Metadata
Assignees
Labels
No labels