AngularJS: is it possible to invalidate a specific form input field from the controller?

I have a text input field for address, whenever the address is entered and search button next to the input field is clicked, I geocode the address and replace the input text with the result from the geocoder. I also set a scope variable 'addressOk'.

is it possible to invalidate this specific form input field according to $scope.addressOk or do I have to write a directive for this address geocoding input that invalidates the form when needed ?

I found the solution, add a name attribute to the <form> and <input>, and then in the controller its possible to do $scope.formName.inputName.$setValidity(errorKey, isValid).

Then, its possible to display errors with something like ng-show="formName.inputName.$error.errorkey"

according to http://docs.angularjs.org/api/ng.directive:form If name attribute is specified, the form controller is published onto the current scope under this name.