From b408d898152cca152ff9994e26c7b5c9e97bd421 Mon Sep 17 00:00:00 2001 From: Timur Sufiev Date: Fri, 9 Jan 2015 04:59:07 -0800 Subject: [PATCH] Load angularjs dynamic templates in run() section Change-Id: Ib0ae4618541a250941b4018cb0b9ffc966527a40 --- extensions/mistral/static/mistral/js/directives.js | 9 +++------ extensions/mistral/static/mistral/js/services.js | 12 +++++++++++- 2 files changed, 14 insertions(+), 7 deletions(-) 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