实施包含另一个 html 的指令

Implementing a directive which includes another html

我想使用以下指令。如果 context.view 等于 XYZ,<tabContent action="XYZ.html"> 将显示 XYZ.html。所以我创建了以下指令:

.directive('tabContent',function(){
    return {
        restrict: 'E',
        template:'<div ng-if="view==\'{{action}}\'" ng-include="\'{{action}}.html\'"></div>',
        link: function(scope, elem, attrs) {
            scope.action = attrs.action;
        }
    }
})

这是正确的方法吗?
谢谢,
奥马尔

首先,如果指令名称是 tabContent,那么 html 标签变为:<tab-content>

那我觉得你的代码有问题,什么view? 那么它应该是这样的:

HTML:

<tab-content action="XYZ.html"></tab-content>

JS:

.directive('tabContent',function(){
    return {
        restrict: 'E',
        template:'<div ng-include="action"></div>',
        link: function(scope, elem, attrs) {
            scope.action = attrs.action;
        }
    }
})

我删除了 ng-if 因为我不知道 view 是什么。