In my directive I have this code:
// hide all drodowns with this attribute
$(document).find('[dropdown]').each(function (index) {
if ($(this).is(':visible')) {
var a = $(this).attr('ng-show');
???
}
});
At the place of the question marks I want to do the following: get the value of the ng-show attribute and set this value to false. The value I get from jQuery is for example this: showActionsDropdown. This value is a variable in my scope.
What I'd like to know is how I can change the value of showActionsDropdown to true.
2 Answers 2
I've found I was looking for. This is the way I accomplished it, using $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);
}
});
Comments
Simple try like this
if ($(this).is(':visible')) {
var a = $(this).attr('ng-show');
$(this).attr('ng-show','false');
}
assign value to ng-show directly like this,or you can directly do like
if ($(this).is(':visible')) {
var a = $(this).attr('ng-show');
$(this).hide();
}
2 Comments
showActionsDropdown is set to true, which will show the dropdown. When I use .hide() the value is still true. So when I click the button again the value becomes false and won't show the dropdown. When I click again, the value becomes true, which will show the dropdown again, but I had to click twice and that's what I don't wantExplore related questions
See similar questions with these tags.
showActionsDropdownvariable directly. You do not change ng-show attribute with jQuery.