在我的指令中,我有这段代码:
// hide all drodowns with this attribute
$(document).find('[dropdown]').each(function (index) {
if ($(this).is(':visible')) {
var a = $(this).attr('ng-show');
???
}
});
在问号的位置我想要执行以下操作:获取ng-show
属性的值并将此值设置为false。我从jQuery获得的值例如是:showActionsDropdown
。该值是我范围内的变量。
我想知道的是如何将showActionsDropdown
的值更改为true。
答案 0 :(得分:3)
我发现我在寻找。这是我使用$parse完成它的方式:
$(document).find('[dropdown]').each(function (index) {
if ($(this).is(':visible')) {
var attrValue = $(this).attr('ng-show');
var model = $parse(attrValue); // note: $parse is injected in the ctor
model.assign(scope, false);
}
});
答案 1 :(得分:0)
像这样简单尝试
if ($(this).is(':visible')) {
var a = $(this).attr('ng-show');
$(this).attr('ng-show','false');
}
像这样直接为ng-show赋值,或者你可以直接像
那样if ($(this).is(':visible')) {
var a = $(this).attr('ng-show');
$(this).hide();
}