Skip to content

Commit 2e749ee

Browse files
authored
Merge pull request #213 from nhardy/master
getTemplate() should always return a Promise
2 parents d29be43 + ea0bdec commit 2e749ee

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

lib/angular-tooltips.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@
269269
}
270270
};
271271
}
272-
, tooltipDirective = /*@ngInject*/ ['$log', '$http', '$compile', '$timeout', '$controller', '$injector', 'tooltipsConf', '$templateCache', function tooltipDirective($log, $http, $compile, $timeout, $controller, $injector, tooltipsConf, $templateCache) {
272+
, tooltipDirective = /*@ngInject*/ ['$log', '$http', '$compile', '$timeout', '$controller', '$injector', 'tooltipsConf', '$templateCache', '$q', function tooltipDirective($log, $http, $compile, $timeout, $controller, $injector, tooltipsConf, $templateCache, $q) {
273273

274274
var linkingFunction = function linkingFunction($scope, $element, $attrs, $controllerDirective, $transcludeFunc) {
275275

@@ -531,17 +531,17 @@
531531

532532
var template = $templateCache.get(tooltipTemplateUrl);
533533

534-
if (typeof template === 'undefined') {
535-
536-
// How should failing to load the template be handled?
537-
template = $http.get(tooltipTemplateUrl).then(function onGetTemplateSuccess(response) {
538-
539-
return response.data;
540-
});
541-
$templateCache.put(tooltipTemplateUrl, template);
534+
if (typeof template !== 'undefined') {
535+
// Wrap template in a Promise so that getTemplate always returns a Promise
536+
return $q.resolve(template);
542537
}
543-
544-
return template;
538+
539+
// How should failing to load the template be handled?
540+
return $http.get(tooltipTemplateUrl).then(function onGetTemplateSuccess(response) {
541+
$templateCache.put(tooltipTemplateUrl, response.data);
542+
543+
return response.data;
544+
});
545545
}
546546
, onTooltipTemplateChange = function onTooltipTemplateChange(newValue) {
547547

0 commit comments

Comments
 (0)