I am currently working on an angular.js controller called loginErrorCtrl
, which is responsible for redirecting to a specific view (/menu
) when the data entered into an input matches a predefined string in the application (Data.serverToken
).
function loginErrorCtrl($scope, Data, $location) {
$scope.data = Data;
$scope.validateToken = function(token) {
if (token != null) {
if (token.length == 4) {
if (token == Data.serverToken) {
$location.path('/menu');
} else {
//error
return "Invalid Token please try again";
}
}
}
};
}
However, I have encountered an issue where the redirection using $location.path('/menu')
does not occur immediately after entering the correct token in the input box. It only redirects after pressing the backspace key. How can I resolve this and ensure that the redirection happens upon successful validation of the token?
If you would like to view the code on Plunker, you can do so here: Angular JS routing