I know that there's a similar question on Stack Overflow but it's not quite what I am looking for. The ng-include alows me to dynamically change the path but then I can't access scope variables.
Basically I would like to dynamically assign a template URL to a directive through an AJAX call. Unfortunately I can't seem to bind the directive attribute to an actual scope variable.
app.directive('appsdirective', function() {
return {
templateUrl : function(elem,attrs) {
// attrs.templateUrl contains "app.appPath" rather than the content itself
return attrs.templateUrl;
},
restrict : 'EA',
scope : false
}
});
<appsdirective template-url="{{app.appPath}}"></appsdirective>
$scope.app is a main controller variable that is undefined at the beginning but gets initialized later through an AJAX request. I also tried manually initializing the variable but it didn't help and I get this obvious error in the console:
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:8080/%7B%7Bapp.appPath%7D%7D