So, I'm looking to create my first angular directive for a validation check. Essentially I want to ensure an user name is unique. This answer is perfect for my first pass, and works as expected for creating a new user.
I'd like this also to work for users who want to change their user name. On the server side, I would write code to check that the user name doesn't exist in the database for any user other than the current user. In other words, if a user is modifying their profile, and the form has a group of fields that include user name, I don't want to form to be invalid if the username already exists, since the reason it exists is that the current user already has it.
So what I would like to do is pass the userId (an integer PK) as a parameter in the ajax call in addition to the user name. The userId exists on the $scope, but I don't know how to modify the directive to allow me to pass additional information.
I would imagine the markup would look something like the following?
<input type="email" ng-model="userEmail"
name="userEmail" required unique-email="userId"/>