Closed viztastic closed 8 years ago
Is there a better way of excluding specific states from registering in $previousState ?
No, there is no way to get $previousState to do what you want, sorry. I suggest doing it yourself. Here is an example decorating your state definitions with some custom data, then keeping track and exposing a simple API.
// Decorate the state definitions
.state('stateA', {
data: { secure: true }
});
module.factory('SecureStates', function($rootScope, $state) {
// Update service.previous whenever they go to a secure state
$rootScope.$on('$stateChangeSuccess', function(evt, toState, toParams) {
if (toState.data.secure) service.previous = { state: toState, params: toParams };
});
var service = {
previous: null,
goPrevious: function() {
if (service.previous) $state.go(service.previous.state, service.previous.params);
}
};
return service;
});
module.controller('LoginController', function(SecureStates, $scope, AuthService) {
$scope.login = function(user, pass) {
AuthService.authenticate(user, pass).then(SecureStates.goPrevious)(;
}
});
Hi,
This is my use case:
Currently I tried to implement this by way of:
With the hope that the "menucaller" memo will only save states of anything but those I want to exclude.. but it seems to not be the case.
Is there a better way of excluding specific states from registering in $previousState ?