diff --git a/extensions/mistral/static/mistral/js/directives.js b/extensions/mistral/static/mistral/js/directives.js index d0e1dc0..213e2b5 100644 --- a/extensions/mistral/static/mistral/js/directives.js +++ b/extensions/mistral/static/mistral/js/directives.js @@ -101,12 +101,9 @@ return { restrict: 'E', scope: true, - link: function(scope, element, attrs) { - $http.get( - '/static/mistral/js/angular-templates/fields/' + scope.spec.type + '.html', - {cache: $templateCache}).success(function(templateContent) { - element.replaceWith($compile(templateContent)(scope)); - }); + link: function(scope, element) { + var template = $templateCache.get(scope.spec.type); + element.replaceWith($compile(template)(scope)); } } }) diff --git a/extensions/mistral/static/mistral/js/services.js b/extensions/mistral/static/mistral/js/services.js index 8ec5cc6..337d261 100644 --- a/extensions/mistral/static/mistral/js/services.js +++ b/extensions/mistral/static/mistral/js/services.js @@ -13,6 +13,16 @@ attrs[attrName] = $parse(attrs[attrName])(); } } - }); + }) + + .run(function($http, $templateCache) { + var fields = ['dictionary', 'frozendict', 'list', 'string', 'varlist']; + fields.forEach(function(field) { + var base = '/static/mistral/js/angular-templates/fields/'; + $http.get(base + field + '.html').success(function(templateContent) { + $templateCache.put(field, templateContent); + }); + }) + }) })(); \ No newline at end of file