Took me forever to figure out what was happening. A standard $ionicPopover was being called and I was getting a
Cannot read property 'show' of undefined
As soon as the controller is entered its checking for a $stateParm - if set, then launch the popover. The problem though is the $ionicPopover template wasn't loaded into the $scope yet so $scope.popover.show() was returning the error.
When I added a setTimeout(function() { $scope.popover.show(); },2000) ; - that delayed things long enough for the popover to be loaded into the scope and allowed it launch.
Even though this bandaid works, I don't like using this method. What other method can I use to ensure the $ionicPopover/$ionicModal are all loaded other code is allowed to execute and reference them?
$ionicPopover.fromTemplateUrl('pushPopover.html', {
scope: $scope,
focusFirstInput:false
}).then(function(popover) {
$scope.popover = popover;
});
$scope.openPopover = function() {
$scope.popover.show(); // calls before popover is loaded causing error
}
$scope.closePopover = function() {
$scope.popover.hide();
}
if ($stateParams.pushAction == 1) {
$scope.pushSub = $stateParams.pushSub ;
$scope.pushMsg = $stateParams.pushMsg ;
$scope.pushCode = $stateParams.pushCode ;
$scope.openPopover() ;
}
In order to get it work, I have to intentionally delay the call with a sloppy timeout:
if ($stateParams.pushAction == 1) {
$scope.pushSub = $stateParams.pushSub ;
$scope.pushMsg = $stateParams.pushMsg ;
$scope.pushCode = $stateParams.pushCode ;
setTimeout(function() {
$scope.openPopover() ;
},2000) ;
}
One technique is to store the promise and chain from it:
Services immediately return promises while
.thenblocks wait for data from the server.