How can I validate so that the botón
does not allow me to change the password until they are equal ?, something with $error
or ng-message
.
I want that when I change the password validate that if there is something in the input and that they are the same, otherwise do not do anything.
var app = angular.module('myApp', []);
app.controller('appController', function ($scope, $http) {
$scope.changePassword = function() {
if ($scope.newPassword == $scope.confirmNewPassword) {
console.log("contraseña son correctas");
}else {
console.log("contraseña no coinciden, vuelva a intentar");
}
}
});
<!DOCTYPE html>
<html>
<head>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script src="script.js"></script>
</head>
<body ng-app="myApp" ng-controller="appController">
<div class="col-sm-12 col-md-12">
<label>Nueva contrasena:</label>
<input type="text" ng-model="newPassword" placeholder="Nueva contrasena" class="form-control" />
</div>
<div class="col-sm-12 col-md-12">
<label>Repetir Contrasena:</label>
<input type="text" ng-model="confirmNewPassword" placeholder="Repetir contrasena" class="form-control" />
</div>
<div class="col-sm-12 col-md-12">
<button type="button" ng-click="changePassword()">Cambiar contrasena</button>
</div>
</body>
</html>