Reputation: 3963
Because every partial template is cached which I don-t want I am doing this
.directive('myMessages', [ function () {
return {
restrict : 'E',
templateUrl : 'wwwroot/base/messages/ui.partial.messages.show.html?v' + Date.now(),
is it possible globally override templateUrl
function and add Date at the end?
I also try this two solutions from the forum but they are never triggered:
$rootScope.$on('$routeChangeStart', function(event, next, current) {
$templateCache.remove(current.templateUrl);
});
$rootScope.$on('$viewContentLoaded', function() {
$templateCache.removeAll();
});
Upvotes: 0
Views: 308
Reputation: 7179
If I'm not wrong, you are trying to use your directive as a banner on top of every page.
It would be the best if you can convince your backend to return you a JSON rather than partial HTML, but I understand that is not always going to happen.
Instead of using templateUrl to achieve this, I would suggest using $http.get
and load it inside the directive.
.directive('myMessages', [ function () {
return {
restrict : 'E',
template : '<div></div>',
link: function(scope, element, attrs){
$http.get('wwwroot/base/messages/ui.partial.messages.show.html?v' + Date.now()).then(function(response.data) {
// if your html contains angular syntax, use $compile
element.html(response.data);
$compile(element.contents())(scope);
// if your html doesn't contain angular syntax, use $sce
// your template needs to be <div ng-bind-html="message"></div>
scope.message = $sce.trustAsHtml(response.data);
});
}
}
]);
Upvotes: 1