I am currently working on a project using AngularJS where the user can activate their account, input their data, and submit JSON data upon completion.
My Goal:
When the user submits valid user data (within the JSON data), they should be redirected to '/form/'. If the data is invalid, display an error message saying 'Invalid Account'.
Current Challenges:
1. If the user enters the correct Membership and Activation number first, they are redirected to '/form/'. However, if the user enters incorrect details first and then correct details later, the redirect does not work.
2. I attempted to implement an invalid alert using an if-else statement, but multiple alerts were triggered simultaneously. I am unsure why this is happening.
I am working on this project on Plnkr, and I would appreciate any assistance and guidance in the right direction. Thank you.
http://plnkr.co/edit/5uPSn2ae0yFjYzujPFWm?p=preview
$scope.findMembership = function() {
angular.forEach($scope.membershipData.membershipNumber, function(value, key) {
if (key === $scope.membershipValue && value[0].activationNumber === $scope.activationValue) {
$location.path("/form/");
}
});
};
Update
formCtrl.controller('activation', function($scope, $location, $rootScope) {
var normalized = Object.keys($scope.membershipData.membershipNumber).map(function(k) {
return { key : k, val : $scope.membershipData.membershipNumber[k][0].activationNumber }
});
normalized = [
{"key":"541","val":"541X"},
{"key":"4692","val":"4692X"},
{"key":"45165","val":"45165X"},
{"key":"5464565","val":"5464565X"},
{"key":"54645651","val":"54645651X"},
{"key":"D4554160N","val":"D4554160NX"}
]
$scope.findMembership = function() {
if (normalized.some(function(o) {
return o.key == $scope.membershipValue && o.val == $scope.activationValue
})) $location.path("/form/")
}
});