ionic (angularjs) - $state.go - Error: transition prevented at $StateProvider.$get ...
Hi everyone!
I'm having problems redirecting $state.go doesn't redirect in one of cases in my app. Details:
www/js/routes.js
...
$stateProvider
.state('login', {
url: '/login',
templateUrl: 'templates/login.html',
controller: 'LoginCtrl'
})
.state('registro', {
url: '/registro',
templateUrl: 'templates/registro.html',
controller: 'registroCtrl'
})
.state('menu', {
url: '/side-menu21',
templateUrl: 'templates/menu.html',
abstract:true
})
.state('menu.miCuenta', {
url: '/myaccount',
views: {
'side-menu21': {
templateUrl: 'templates/miCuenta.html',
controller: 'miCuentaCtrl'
}
}
})
...
www/js/directives.js
...
.directive('showRegistro', function($state) {
return {
link: function($scope, element) {
element.on('click', function() {
console.log("This is shown on console!");
$state.go('registro');
});
}
}
})
...
Message "This is shown on console!" is shown on console but "$state.go('registro')" not works. Debuggin I've found this error trace:
### "Error: transition prevented at $StateProvider.$get (http://localhost:8100/lib/ionic/js/ionic.bundle.js:48931:41) at Object.invoke (http://localhost:8100/lib/ionic/js/ionic.bundle.js:17762:17) at http://localhost:8100/lib/ionic/js/ionic.bundle.js:17580:37 at getService (http://localhost:8100/lib/ionic/js/ionic.bundle.js:17721:39) at Object.invoke (http://localhost:8100/lib/ionic/js/ionic.bundle.js:17753:13) at http://localhost:8100/lib/ionic/js/ionic.bundle.js:17584:79 at forEach (http://localhost:8100/lib/ionic/js/ionic.bundle.js:13648:20) at createInjector (http://localhost:8100/lib/ionic/js/ionic.bundle.js:17584:3) at doBootstrap (http://localhost:8100/lib/ionic/js/ionic.bundle.js:14942:20) at bootstrap (http://localhost:8100/lib/ionic/js/ionic.bundle.js:14963:12)"
On the other hand, once user is logged, redirections to menu option works. In example:
.directive('showProfile', function($state) {
return {
link: function($scope, element) {
element.on('click', function() {
$state.go('menu.miCuenta');
});
}
}
}))
Any ideas?
Thanks in advance!
This is better suited for Stack Overflow http://bit.ly/UIR-SOF
"Transition prevented" is caused by some event handler (yours or ionic's) calling event.preventDefault()
See the source code here: https://github.com/angular-ui/ui-router/blob/b3950ead2c040117101ec48b8e87ef33050af93b/src/state.js#L1093
slider is not not working in angularjs when defualt route date get from home page how to solve this problems
slider is not not working in angularjs when defualt route data get from home page how to solve this problems