Skip to content Skip to sidebar Skip to footer

Dynamic Templateurl For Directive In Ngrepeat In Ngview

I am facing a problem with AngularJS. My application starts, then reaches a specific ngView through ngRoute and calls a controller. when the controller is initialize it retrieves d

Solution 1:

When templateUrl function runs, the attribute values are still not interpolated.

So, you'd need to load the template at link time. You can cheaply re-use ng-include to accomplish that:

.directive("jlTile", function($interpolate){
  return {
    template: '<div ng-include="url"></div>',
    link: function(scope, element, attrs){
      var suffix = $interpolate(attrs.jlTile)(scope);
      scope.url = "/templates/elements/tile-" + suffix + ".html";
    }
  }
});

Post a Comment for "Dynamic Templateurl For Directive In Ngrepeat In Ngview"