Where is it best to handle both error handling, and error display? E.g.
I have a controller:
angular.module('app')
.controller('MyController', function ($scope) {
$scope.form = {
username: ''
};
$scope.login = function () {
doSomething($scope.form.username);
};
});
And a view bound to the controller:
<div ng-controller="MyController">
<input ng-model="username.form" />
<button ng-click="login()">Submit</button>
</div>
If $scope.form.username is blank, this is an error; where is it best to handle this? In the controller, e.g.:
if ($scope.form.username == '') {
// do something here
}
Or just pass the value to doSomething(...) and let that function handle a blank value?
Secondly, what's the best method to update the element (say, to highlight the input red or to show a small message underneath) to indicate that an error has occured?