我有以下指令在点击时打开行菜单:
app.directive('rowDropdownMenuDirective', function(){
return {
restrict: 'AE',
scope: '@',
replace: false,
link: function(scope){
//close row menus
scope.menuIndex = -1
scope.showMenu = function($index){
if(scope.menuIndex == $index){
scope.menuIndex = -1
}else{
scope.menuIndex = $index
}
console.log(scope.menuIndex == $index)
}
},
//templateUrl: 'template.html'
template: "<div class='options-menu'>" +
"<a href='#' title='Options' class='options-menu-toggle' ng-class='{openWidgetButton: menuIndex == $index}' " +
"ng-click='showMenu($index)'>Options</a>" +
"<ul class='options-menu-widget' ng-show='menuIndex == $index'>" +
"<li><a href='#'>Approve</a></li>" +
"<li><a href='#'>Deny</a></li>" +
"<li><a href='#'>Review</a></li>" +
"</ul></div>"
}
})
点击后触发scope.showMenu
功能后,触发ngShow:
ng-show='menuIndex == $index'
但是,只要在单独的click事件的指令中更新menuIndex
值,所有其他指令实例中的menuIndex
的值就不会更新,因此ngShow不会更新。
编辑:
ng-class='{openWidgetButton: menuIndex == $index}'
更新单独的点击事件,因此我认为该问题特定于ngShow