Currently facing an issue: I am working on creating a login form where I need to validate if the username and password entered in the input fields match the values stored in my array of users.
var app = angular.module('myApplication', []);
app.controller('UserListCtrl', function ($scope) {
$scope.usersList = [
{
name: 'Alex',
pass: 2200201
},
{
name: 'Michael',
pass: 1231215
},
{
name: 'John',
pass: 1232116
}
];
$scope.checkInputs = function () {
$scope.searchUser = {
name: $scope.yourName,
pass: $scope.yourPass
};
if ($scope.searchUser.name === $scope.usersList.name) {
console.log($scope.searchUser.name);
} else {
console.log('You are not registered');
}
};
});
Here's how it looks in HTML:
<form ng-submit="checkInputs()">
<input type="text" ng-model="searchUser.yourName"><br>
<input type="text" ng-model="searchUser.yourPass">
<input type="submit" class="button">
</form>