【发布时间】:2015-01-22 23:04:24
【问题描述】:
我有一个扩展和关闭 div 高度的指令。它使用了多次,所以当用户打开一个盒子时,我想关闭其他打开的盒子。我认为最好发出一个事件,但问题是指令随后也会自行关闭,因此无法打开任何 div。
我可以忽略来自同一指令的消息吗?
angular.module('cinemaApp')
.directive('expand', function ($rootScope) {
return {
restrict: 'A',
link: function postLink(scope, element, attrs) {
$rootScope.$on('contract', function(payload) {
element.css('height', attrs.fixedheight);
});
scope.$watch('open', function(value) {
element.css('height', (value ? 'auto' : attrs.fixedheight));
$rootScope.$emit('contract');
});
element.css('height', attrs.fixedheight);
}
};
});
【问题讨论】:
标签: javascript angularjs events dom-events