Can you change templateUrl on the fly?

前端 未结 7 2209
时光取名叫无心
时光取名叫无心 2020-11-29 01:55

Is it possible to change templateUrl on the fly by passing values in the directive\'s scope? I want to pass data to controller that will render the page based on the data th

7条回答
  •  Happy的楠姐
    2020-11-29 02:18

    I had similar problem

     return {
            restrict: 'AE',
            templateUrl: function(elm,attrs){return (attrs.scrolled='scrolled' ?'parts/scrolledNav.php':'parts/nav.php')},
            replace: true,

    partnersSite.directive('navMenu', function () {
        return {
            restrict: 'AE',
            templateUrl: function(elm,attrs){return (attrs.scrolled='scrolled' ?'parts/scrolledNav.php':'parts/nav.php')},
            replace: true,
            link: function (scope, elm, attrs) {
                scope.hidden = true;
                //other logics
            }
        };
    });

提交回复
热议问题