Setting focus to input element
HTML
<div ng-controller="testCtrl">
<table>
<tr ng-repeat="student in students">
<td>{{student.name}}</td>
<td><input type="text" focus-me="student.focus"></td>
</tr>
</table>
</div>
CSS
.focus-me{
border:1px solid red;
}
JavaScript
var app = angular.module('testApp',[]);
app.controller('testCtrl', function($scope){
$scope.students = [
{
name : 'Alpha',
focus:false
},
{
name : 'Beta',
focus:true
},
{
name : 'Gamma',
focus:false
}
]
})
app.directive('focusMe',function($parse){
return {
restrict:'AEC',
link: function(scope, element,attributes){
if ($parse(attributes.focusMe)(scope)) {
element[0].focus();
}
}
}
})