Javascript AngularJS指令-关于转置内容的指令
请看上面的图片。有没有办法将模板dom中的指令绑定到父指令的作用域?我在ng transclude中也看到过这种行为,上面的内容非常简单。我已经读到,转置内容位于指令作用域的同级作用域中,但$$nextSibling似乎也不是诀窍。使用指令:Javascript AngularJS指令-关于转置内容的指令,javascript,angularjs,scope,directive,Javascript,Angularjs,Scope,Directive,请看上面的图片。有没有办法将模板dom中的指令绑定到父指令的作用域?我在ng transclude中也看到过这种行为,上面的内容非常简单。我已经读到,转置内容位于指令作用域的同级作用域中,但$$nextSibling似乎也不是诀窍。使用指令: app.directive('accordion', function($compile) { return { restrict: 'C', scope: { }, link: function(s
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);
});
});
}
};
});