我正在使用Bootstrap UI的手风琴指令。这使用引擎盖下的翻译。我有一些需要重复的逻辑,所以我试图创建一个包装手风琴的指令,它也使用了包含。
<div>
<div accordion>
<div accordion-group is-open="isOpen">
<div accordion-heading>
<span class="glyphicon" ng-class="{'glyphicon-minus-sign': isOpen, 'glyphicon-plus-sign': !isOpen}"></span>
<strong>{{headerTitle}}</strong>
</div>
<div ng-transclude></div>
</div>
</div>
</div>
这是JavaScript:
application.directive('collapsePanel', ['baseUrl', function (baseUrl) {
return {
restrict: 'A',
templateUrl: baseUrl + 'content/templates/collapse_panel.html',
replace: true,
transclude: true,
scope: {
headerTitle: '@'
},
controller: ['$scope', function ($scope) {
$scope.isOpen = false;
}]
};
}]);
它应该像使用一样简单:
<div collapse-panel header-title="Title">
{{scopeVariable}}
</div>
假设scopeVariable
在我的控制器中,我认为它的值会出现。据我所知,范围属于collapse-panel
而不是外部范围。这几乎就像嵌套的转换指令导致了我的问题。
这样的嵌套转换是否有诀窍?