I am using angular reactive formsGroup and formControl. my requirement is the value of each formControl should be unique and if user try to add duplicate value then it should show validation error.
FormGroup Creation
this.contryCodeForm = this.formBuilder.group({
US: ['+1', , [],[this.uniqueValidator, Validators.required]],
UK: ['+44', [],[this.uniqueValidator, Validators.required]],
India: ['+91', [],[this.uniqueValidator, Validators.required]],
email: ['+61', [],[this.uniqueValidator, Validators.required]]
});]
I want to add validation if any one try to edit the value which already taken by other country.
I have tried to implement the this.uniqueValidator
const values = Object.keys(formGroup.value).map(key => formGroup.value[key])
const filtered = values.filter(x=>x === control.value);
if (filtered.length > 1) {
return {message: "This field must be unique value"}
}
but it does not work
any help appreciated

I think you should do this: