Download angular 1.5 component template via promise

In Angular 1.5, I want to load a template using custom promises. The example code I would like to run is

var module = angular.module("myApp", []); module.component("component", { template: ["$q", function ($q) { var defer = $q.defer(); setTimeout(function () { defer.resolve("<p>Hello world</p>"); }, 100) return defer.promise; }], controller: function () { } }); 

The reason I want to do this is to download the template from the iframe proxy.

If there is any way to provide my custom template resolver for a promise that would be too big.

+5
source share
1 answer

I solved the problem by replacing $ templateRequestService angular with a decorator.

See the sample code below:

 module.config(["$provide", function ($provide) { $provide.decorator("$templateRequest", [ "$delegate", "$q", // DI specifications function ($delegate, $q) { // 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; // Make an async call return defer.promise; } // return the modified delegate function return $delegate; }]); }]); 
+3
source

All Articles