This is quite an infamous issue with Angular, and there's so many articles explaining this on the web, but please just hear me out. I've read those, and they didn't work. I have the following (I'm just simplifying here):
View:
<div ng-hide="{{beHidden}}"></div>
Controller:
// Set beHidden to initially be false (This works and reflects when set to true as well)
$scope.beHidden = false;
// First we display a popup asking the user to choose whether the div should be hidden
var confirmPopup = $ionicPopup.confirm({
title: 'Hidden Div',
template: 'Do you want to hide the div?',
cancelText: 'No',
okText: 'Yes'
}).then(function(res) {
if(res) {
// User chose to hide div
$timeout(function() {
$scope.beHidden = true;
});
} else {
// User chose NOT to hide div
$timeout(function() {
$scope.beHidden = false;
});
}
});
Now that doesn't work. I've read that I should use the $scope.$apply method, but when I did that I got the $digest already in progress error. To that they say that you should actually use $timeout(function() { // do stuff }); And while that doesn't throw any errors, the view simply doesn't update to hide the div when that's what the user chose.. Any ideas?
Also, yes I am injecting $timeout into the controller correctly...