$templateCache
次のように、モジュールの実行ブロックにテンプレートをロードしようとしています。
angular.module('myapp').run(function($http, $templateCache, $timeout) {
var templateLocation = 'location/to/template.html';
$http.get(templateLocation).them(function(response) {
$templateCache.put(templateLocation, response.data);
)};
}
これにより、テンプレートが templateCache に読み込まれます。ただし、ディレクティブで使用しようとすると。$http
promise が解決される前にディレクティブが読み込まれるため、読み込まれません。
これがディレクティブのコードです
angular.module('myApp').directive('myDirective, directiveFn);
directiveFn.$inject = ["$templateCache"]
function directiveFn($templateCache) {
var templateLocation = 'location/to/template.html';
return {
restrict: 'EA'
scope: {
thing1: "="
}
template: $templateCache.get(templateLocation)
}
}
これを行うためのより良い方法/場所はありますか?