我正在尝试为可在我的应用程序中使用的抽屉创建一个指令。我想做的是:当用户打开一个抽屉时,我需要关闭任何其他当前打开的抽屉。
这是我当前的代码:
标记
<a href="javascript:;" id="my_switch">
Click me to toggle the drawer!
</a>
<drawer data-switch="#my_switch">
Content of the first drawer
</drawer>
<a href="javascript:;" id="my_other_switch">
Click me to toggle the other drawer!
</a>
<drawer>
Content of the second drawer
</drawer>
抽屉.html
<div class="drawer_container">
<div class="drawer" ng-transclude>
</div>
</div>
指示
MyApp.directive('drawer', function(DrawerService){
return {
restrict: 'AE',
replace: true,
transclude: true,
templateUrl: 'drawer.html',
link: function(scope, element, attributes){
var drawer_switch = $(attributes.switch);
var drawer = $(element).find('.drawer');
var toggle = function(event){
drawer.toggle();
};
drawer_switch.bind('click', toggle);
}
};
});
仅使用指令打开一个抽屉是否可能导致其余抽屉关闭?