angularjs – 角度指令不同的模板
发布时间:2020-12-17 08:34:29 所属栏目:安全 来源:网络整理
导读:我有一个指令myDirective与变量类型。如果我运行 my-directive type =“X”我想让指令使用templateUrl:x-template.html。 如果我做 my-directive type =“Y”我想让指令使用templateUrl:y-template.html。 这是我当前的指令。 app.directive('myDirective'
我有一个指令myDirective与变量类型。如果我运行< my-directive type =“X”>我想让指令使用templateUrl:x-template.html。
如果我做< my-directive type =“Y”>我想让指令使用templateUrl:y-template.html。 这是我当前的指令。 app.directive('myDirective',function() { var myDirective = { templateUrl: 'X-template.html',restrict: 'E',scope: { type: '=' },}; return myDirective; }); 我读通过stackoverflow和有角度的文档,但没有发现任何我需要的。 我现在正试图做一些类似的事情: if ($scope.type === 'X') { templateUrl: 'X-template.html',} else if ($scope.type === 'Y') { templateUrl: 'Y-template.html',} 但不知道在哪里做。 你知道这是可能和如何?
你可以在
this issue左右使用ng-include里面编译:
app.directive('myDirective',function() { return { restrict: 'E',compile: function(element,attrs) { element.append('<div ng-include="'' + attrs.type + '-template.html'"></div>'); } } }); fiddle (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |