I've to use AngularJS 1.7 for a project where I have a form and have to validate an input field to be required, to have a particular pattern and to have unique values. For this I'm doing this :
input#item-name(
name="name",
type="text",
required,
ng-pattern="$ctrl.pattern.id",
ng-model="$ctrl.item.name",
)
div(ng-messages="addItemForm.name.$error")
div(ng-messages-include="error-messages")
I've covered the required and the pattern one. But not able to include the unique validation.
I have an array with all the existing values :
this.existingItems = ['A','B','C];
I've tried something like this but did not work:
input#item-name(
name="name",
type="text",
required,
ng-pattern="$ctrl.pattern.id",
ng-model="$ctrl.item.name",
ng-unique="$ctrl.existingItems",
)
div(ng-messages="addItemForm.name.$error")
div(ng-messages-include="error-messages")
I've used this part of code inside a component and pointed "this" to "$ctrl".