Skip to content

Instantly share code, notes, and snippets.

@jigargandhi
Created June 26, 2016 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jigargandhi/44419719963e1664333e9c09ef6a5807 to your computer and use it in GitHub Desktop.
Save jigargandhi/44419719963e1664333e9c09ef6a5807 to your computer and use it in GitHub Desktop.
Angular custom template request provider
module.config(["$provide", function ($provide) {
$provide.decorator("$templateRequest", [
"$delegate", "$q", "$templateCache",// DI specifications
function ($delegate, $q,$templateCache) {
// replace the delegate function
$delegate = function (tpl) {
var defer = $q.defer();
// convert the tpl from trustedvaluetoken to string
if (typeof (tpl) !== "string" || !!$templateCache.get(tpl)) {
tpl = $sce.getTrustedResourceUrl(tpl);
}
// make proxy call and resolve the promise;
return defer.promise;
}
// return the modified delegate function
return $delegate;
}]);
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment