0

This is an example of my code where I want to switch a templateUrl. This works only if you refresh the page while holding the data in localstorage or backend.

app.directive('myPanel', ['myService', function(myService) {
    if(myService.isThisTrue()) {
        return {
            restrict: 'E',
            templateUrl: '/views/isTrue.html'
        }
    } else {
        return {
            restrict: 'E',
            templateUrl: '/views/isFalse.html'
        }
    }
}]);

I did not find a decent way yet to do it better. Does anyone have a better solution?

1

1 Answer 1

2

templateUrl can be a function where you return the url string

app.directive('myPanel', ['myService',function(myService) {
    return {
      restrict: 'E',
      templateUrl: function() {
        return myService.isThisTrue() ? '/views/isTrue.html' : '/views/isFalse.html';
      }
    }
  }
])
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.