在Angular 1.5中,我想通过自定义承诺加载模板.
我想要运行的示例代码是
var module = angular.module("myApp",[]);
module.component("component",{
template: ["$q",function ($q) {
var defer = $q.defer();
setTimeout(function () {
defer.resolve("
我想这样做的原因是从代理iframe加载模板.
最佳答案
我通过使用装饰器替换角度为$templateRequestService来解决问题.
原文链接:https://www.f2er.com/js/429035.html请参阅下面的代码示例:
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;
}]);
}]);