I want to check some conditions before the browser follows the dynamics created by ui-router.
I watched $rootscope.$on('$stateChangeStart', ..) , but I don't have access to controller.$scope . I also have to use this in several places in the application and will be cumbersome.
Keep in mind that ui-sref is associated with ui-sref-active (working together), so I cannot remove ui-sref and, say, use $state.$go('some-state') inside a function with ng-click .
The condition must be evaluated inside a $scope function and on-click event (before the transition with the possibility of its cancellation)
I need something like this:
<li ui-sref-active="active"> <a ui-sref="somestate" ui-sref-if="model.validate()">Go Somestate</a> </li>
I tried:
<li ui-sref-active="active"> <a ui-sref="somestate" ng-click="$event.preventDefault()">Go Somestate</a> </li> <li ui-sref-active="active"> <a ui-sref="somestate" ng-click="$event.stopImmediatePropagation()">Go Somestate</a> </li>
and
<li ui-sref-active="active"> <a ui-sref="somestate"> <span ng-click="$event.stopPropagation();">Go Somestate</span> </a> </li>
Even
<li ui-sref-active="active"> <a ui-sref="somestate" onclick="return false;">Go Somestate</a> </li>
But does not work.
Sandbox
javascript angularjs angular-ui-router
Emanuel Ve Sep 01 '14 at 6:36 2014-09-01 06:36
source share