Modal on rootscope


#1

So, I have a modal initialized inside my app.run:

.run(function($ionicModal, $rootScope){
  $ionicModal.fromTemplateUrl('templates/modal.html', {
    scope: $rootScope
  }).then(function(modal) {
    $rootScope.modal = modal;
  });
  
    $rootScope.someFunction = function(){
     $rootScope.modal.show();
   }
}) 

So in any of my views if I fire someFunction() the modal arises. But the problem is behind the modal, the state transits to the state defined in $urlRouterProvide.otherwise("stateName") . If I close the modal, I can see that I will be in the 'home' state regardless of what my previous state was.


#2

I was stupid enough to assign href attribute with value set to '#" to links that open the modal.


#3

And i mention it again and again and again…

do not use href-attribute in angularjs apps.
in ordinary angularjs apps use ng-href.

In ionic apps you are using the ui-router so it is recommended to use ui-sref="" to navigate to states.

Or ng-click with a function that changes the state :wink:


#4

@bengtler yeah naturally I use ui-sref. but the href value got in there with the default value of # because of the sublime text snippet that I had written previously and used it pretty blindly in my app. :wink:


#5

Can you explain why to do this? Thx!