Say I have a model object with the attribute favoriteColors
{
...
favoriteColors: ['red', 'green', 'blue']
....
}
I expose them to the user with an ng-repeat
<form name=userForm>
...
<ul>
<li ng-repeat=color in user.favoriteColors>
<input type=text ng-model=color />
<a href= ng-click=delete(color)>remove</a>
</li>
</ul>
<a href= ng-click=add()>Add a new favorite color</a>
...
</form>
I would like to be able to check the validity of the favoriteColors
field doing something like this
<div ng-show=userForm.favoriteColors.$error>
You must have at least one favorite color
</div>
It doesn't seem possible to do this using a built in validator, and I'm not sure on which element I would put a custom directive in order to get the ngModelController
for favoriteColors
.