I am encountering a problem with my Ionic application that features multiple Angular controllers. Specifically, I have a LoginCtrl and RegisterCtrl controller set up. The issue arises when I try to trigger a modal with a slider from the RegisterCtrl by using $emit within the LoginCtrl:
Modal Template HTML
<!-- This is a simplified version of the code -->
<ion-content class="register-wrapper">
<ion-slide-box delegate-handle="registerSlider" show-pager="false">
<ion-slide class="padding">
Slide 1
</ion-slide>
<ion-slide class="padding">
Slide 2
</ion-slide>
<ion-slide class="padding">
Slide 3
</ion-slide>
</ion-slide-box>
</ion-content>
LoginCrtl
$rootScope.$emit("showRegisterPopup", {data:'somedata'});
RegisterCrtl
// Below is an abbreviated version of the code
$ionicModal.fromTemplateUrl('templates/modals/register-form1.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function (modal) {
$scope.modal = modal;
$scope.registerModalSlider = $ionicSlideBoxDelegate.$getByHandle('registerSlider');
$scope.registerModalSlider.enableSlide(false);
});
$rootScope.$on("showRegisterPopup", function(emitEvent, somedata){
if ($scope.registerModalSlider){
$timeout(function({
$scope.registerModalSlider.slide(2);
},200);
}
rc.showRegister();
});
Unfortunately, when attempting to execute the .slide() function of the slider, it fails to navigate to the designated page and prompts the error message below:
Delegate for handle "registerSlider" could not find a corresponding element with delegate-handle="registerSlider"! slide() was not called!
Possible cause: If you are calling slide() immediately, and your element with delegate-handle="registerSlider" is a child of your controller, then your element may not be compiled yet. Put a $timeout around your call to slide() and try again.
This error persists even though I have already defined the delegate-handle in the HTML and included a timeout around the .slide() method call.