ui-router
ui-router copied to clipboard
how capture route error when $stateChangeError ?
config route
$stateProvider.state('categories All', {
url: '/categories',
templateUrl: 'categories/views/index.html',
resolve: {
loadRoute: app.loadRoute
}
});
init error
app.loadRoute = function ($q, $timeout,$location,Global) {
// Initialize a new promise
var deferred = $q.defer();
// Is country select
$timeout(deferred.reject);
return deferred.promise;
};
catch error
function(event, toState, toParams, fromState, fromParams) {
});
now how catch route error?
Example
/categories?test=1&value=2 how catch this route? and not the config route
thx.
Errors in a resolve will cause $state to fire the $stateChangeError event.
So you could listen to the event:
module.run(['$rootScope', function($rootScope){
$rootScope.$on('$stateChangeError', function (event, toState, toParams, fromState, fromParams, error) {
if(toState.name == 'Categories')
{
// Do Something
}
});
}]);
Also I wouldn't use a space in your state name. I don't even know if this is supported.
Thanks for the answer, @acollard. @jcsena Please take future support questions to StackOverflow, thanks.
Great thank you so much 👍 @acollard