Stop checker for ion-item?


#1

Hi there I’m new to Ionic.

I want to do something similar to below code, ie. confirm the user before switching to another view.

  <ion-item ng-repeat="task in tasks" type="item-text-wrap" href="#/tab/tasks/{{task.id}}" ng-click="confirm('Are you sure?')">
     // Some codes...  
  </ion-item>

But I found although the confirm box pops out, but the view has already move to another page before the user give response.

Is there any way in Ionic to solve this problem?


#2

First do not use href in ionic apps.
AngularJS provides ngHref and ui-Router the ui-sref directives.
https://docs.angularjs.org/api/ng/directive/ngHref
http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.directive:ui-sref

To solve your problem:

  1. remove href
  2. if you are opening a popup the use has to confirm you can add buttons with custom actions
    http://ionicframework.com/docs/api/service/$ionicPopup/
    if the user confirms through a button --> redirect programmatically with $state.go(“yourStateName”)
    http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$state