Dynamic templateUrl for directive in ngRepeat in ngView

前端 未结 1 1982
刺人心
刺人心 2021-01-29 04:33

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 retrieve

1条回答
  •  迷失自我
    2021-01-29 05:28

    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: '
    ', link: function(scope, element, attrs){ var suffix = $interpolate(attrs.jlTile)(scope); scope.url = "/templates/elements/tile-" + suffix + ".html"; } } });

    0 讨论(0)
提交回复
热议问题