Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
它';是否可以通过angularjs指令中的属性更改templateURL?_Angularjs_Angularjs Directive_Attributes - Fatal编程技术网

它';是否可以通过angularjs指令中的属性更改templateURL?

它';是否可以通过angularjs指令中的属性更改templateURL?,angularjs,angularjs-directive,attributes,Angularjs,Angularjs Directive,Attributes,我有以下指示: (function() { 'use strict'; function header() { return { templateUrl: '/app/home/homeheader.html' }; } angular.module('app').directive('appheader', header); })(); 由于我需要根据使用它的页面更改标题,我想如果我可以在DOM中执行以下操作: index.html <

我有以下指示:

(function() {

  'use strict';
  function header() {
    return {
      templateUrl: '/app/home/homeheader.html'
    };
  }
   angular.module('app').directive('appheader', header);
})();
由于我需要根据使用它的页面更改标题,我想如果我可以在DOM中执行以下操作:

index.html

 <appheader page="index"></appheader>

signUp.html

 <appheader page="signUp"></appheader>

然后在指令中,指定我想要的模板


我在网上读了一些,但没有找到任何解决办法。有很多这样的函数

templateUrl

中给出的示例如下所示:


angular.module('docsTemplateUrlDirective',[])
.controller('controller',['$scope',function($scope){
$scope.customer={
名字:“娜奥米”,
地址:“1600圆形剧场”
};
}])
.directive('myCustomer',function(){
返回{
templateUrl:函数(元素、属性){
返回'customer-'+attr.type+'.html';
}
};
});

您可以将函数传递到
模板URL
,检查
页面
属性,尽情发挥想象力

请看一下文档

下面是一个让您开始学习的示例:

(function() {

  'use strict';

  function header() {
    return {
      templateUrl: function(elem, attrs) {

        // check the attribute value
        if (attrs.page === "home") {
          return '/app/home/homeheader.html';
        } else {
          return '/app/home/signupheader.html';
        }

        // OR use the attribute value as part of the template
        return '/app/home/' + attrs.page + 'header.html';

      }
    };
  }

  angular.module('app').directive('appheader', header);

})();