I have a button that shows a dropdown on click. Each element of the dropdown spawns a ui dialog when clicked. When the ui is opened, the corresponding item in the dropdown is checked. Clicking the element in the dropdown again will close the dialog, and uncheck it in the list.
The dialog can also be closed with an 'X' button on the dialog. I need this closing action to also uncheck the corresponding element in the dropdown. This is what I have inside of a controller:
<div class="dropdown">
<button type="button" class="btn btn-default dropdown-toggle" style="width:100px">
<img src="/UIDemo/images/maps-icon.png" style="padding-right:3px" />
Data Grid
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="#" ng-click="showRouteFeature = !showRouteFeature;
openCloseGrid('routeFeature', showRouteFeature);">
<span ng-class=
"{'glyphicon glyphicon-ok icon-ok check-mark': showRouteFeature,
'glyphicon no-icon': !showRouteFeature}">
</span>
<span class="text">Route Feature</span></a></li>
</ul>
</div>
And in my .js file I have an on close event:
$(document).on('click', '.ui-dialog-titlebar-close', function () {
$scope.showRouteFeature = false;
$scope.apply();
});
The formatting is a little sketchy but I did what I could. When I click an option in the drop down it sets a toggle (established by ng-click" on showRouteFeature
from true to false and vice versa. When I click the 'X' on the dialog, it sets $scope.showRouteFeature
to false, which should uncheck the element in the dropdown. I can see in the console that $scope.showRouteFeature
is in fact set to false when I click the 'X'.
I've found this question, How can I tell AngularJS to "refresh", and this post, http://jimhoskins.com/2012/12/17/angularjs-and-apply.html, on the issue, which is why I have $scope.apply()
after I set the variable to false. However, it's just not refreshing my dropdown. Any insight would be appreciated.