【问题标题】:AngularJS directives - directives on transcluded contentAngularJS 指令 - 嵌入内容的指令
【发布时间】:2014-01-15 06:54:15
【问题描述】:
【问题讨论】:
标签:
javascript
angularjs
scope
directive
【解决方案1】:
使用指令:
app.directive('accordion', function($compile) {
return {
restrict: 'C',
scope: {
},
link: function(scope, elem, attrs){
scope.showSection = false;
elem.find('p').attr('ng-show', 'false');
$compile(elem.find('p'))(scope)
elem.find('h1, h2').bind('click', function () {
scope.$apply(function(){
scope.showSection = !scope.showSection;
elem.find('p').attr('ng-show', 'showSection');
$compile(elem.find('p'))(scope);
});
});
}
};
});
plunkr