在我的指令中我有这样的代码:
// 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。
发布于 2013-06-14 15:58:30
我找到了我要找的。这是我使用$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);
}
});发布于 2013-06-14 15:15:00
像这样简单的尝试
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();
}https://stackoverflow.com/questions/17103020
复制相似问题