0

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();
       });
mbrc
  • 3,523
  • 13
  • 40
  • 64
  • Possible duplicate of [Disable template caching in AngularJS with ui-router](http://stackoverflow.com/questions/23589843/disable-template-caching-in-angularjs-with-ui-router) – lenilsondc Nov 08 '16 at 18:59
  • Where are you putting that code? I do more or less the same thing in my app.run function and it works fine, every time a view is loaded it runs. – Tim Consolazio Nov 08 '16 at 19:03

1 Answers1

1

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);
            });
        }
    }
]);
Icycool
  • 7,099
  • 1
  • 25
  • 33