Page tree
Skip to end of metadata
Go to start of metadata


Please read about how directives can communicate in angular before getting started.


It's highly recommended to study angular docs on form and formController before getting started.

Match Validator

When providing a registration form, it's common to repeat password field in order to verify that there were no typo in the entered password. This field is valid only when it matches the value of password field. So we want to develop a matches directive which adds this validator to ngModel. ngModel will run our validator whenever model value changes. Note that for our validator, it's not sufficient to validate on changes of model value (why?)

matches directive should be used like this:

<form name="myForm">
	<input class="form-control" type="password" name="password" ng-model="user.password" />
	<input class="form-control" type="password" name="passwordConf" ng-model="user.passwordConfirmation" matches="user.password" />
	<div class="alert alert-danger" ng-if="myForm.passwordConf.$error.matches">
		Passwords doesn't match!


You can fork the plunk below as a starting point:

  • No labels