Angular: Autofocus example
http://angularjs.org/
HTML
<div ng-controller="MyCtrl">
<form>
<h3>{{status}}</h3>
<p><input type="text" autofocus="true" placeholder="Username"/></p>
<p><input type="password" placeholder="Password" ng-model="password"/></p>
<p><input type="submit" value="Sign In" ng-click="submit()" /></p>
</form>
</div>
JavaScript
var myApp = angular.module('myApp',[]);
//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});
function MyCtrl($scope) {
$scope.username = '';
$scope.password = '';
$scope.status = '';
$scope.submit = function() {
$scope.status = 'Invalid credentials';
$scope.password = '';
// !!!!!!!!!!!!!!!!!!!!!!!!!!!
// What can I do here to set the focus to the password field
// without violating the controller --> dom taboo?
// !!!!!!!!!!!!!!!!!!!!!!!!!!!
}
}