I am using ng-repeat to create a bunch of inputs. The ng-repeat loops through an array to know how many inputs to produce. The problem comes when I click a button and it pushes a new input into the ng-repeat array, this updates the view and a new input is visible. However, I want to gain focus of this new input. How can I do this? Here is my current code,
JS Controller
app.controller('setCtrl', ['$scope', function($scope) {
$scope.inputs = [];
var inputCounter = 7;
for(var i = 1; i <= 7; i++) $scope.inputs.push( {counter: i, first: '', second: ''} );
// Function to add new input and then gain focus of new input
$scope.addInput = function() {
$scope.inputs.push( {counter: ++inputCounter, first: '', second: ''} );
var focus = "#input" + inputCounter;
$(focus).focus();
}
}]);
HTML / ng-repeat
<div ng-repeat="input in inputs" class="col-xs-12" style="padding-top:12px;">
<div class="col-xs-6 input-wrapper-left">
<div class="input-counter">
{{input.counter}}
</div>
<div id="input{{input.counter}}" class="input-input input-left" contenteditable>
</div>
</div>
</div>
Currently, the above code creates the new input but it will not focus it.