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();
       });
2
  • Possible duplicate of Disable template caching in AngularJS with ui-router Commented Nov 8, 2016 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. Commented Nov 8, 2016 at 19:03

1 Answer 1

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);
            });
        }
    }
]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.