This question has already been answered:
Good day. A question. How to make a directive on an angular for validating the comparison of the entered data (if they are equal - well, not equal - disable buttons). My option for some reason does not work ..
Js
function personalController($scope, personalService) { $scope.changePassword = function () { $scope.oldPassword; $scope.newPassword; $scope.confirmNewPassword; $scope.myCompare = function() { return angular.equals($scope.newPassword, $scope.confirmNewPassword); }; } angular.module('appPersonal').directive('equalPass', function() { return { require: 'ngModel', link: function(scope, elm, attrs, ctrl) { ctrl.$parsers.unshift(function(equalPass) { ctrl.$setValidity('equalPass', $scope.myCompare()); }); } }; }); angular.module('appPersonal') .controller('personalController', ['$scope', 'personalService',personalController]); html
<input ng-model="confirmNewPassword" type="password" placeholder="confirm new password" name="confirmNewPassword" required equalPass><br> <span ng-show="recoverPassword.confirmNewPassword.$error.equalPass" class="text-danger">New password and confirm password mast be equals!</span>
myCompareis described in the Osprey, and trying to be called as a simple function - Grundy$scope- you have thescopeparameter on$scope- Grundy