I have a requirement when I need to focus on a specific line when items are displayed using ng-repeat.
Let's say I have a list of 100 elements with each element having a field, itemIdfrom 1 to 100, itemNameand isAvailable. This list is retrieved from the server using an ajax call from the angularjs service I wrote. The controller, in turn, uses this service to call ajax. When the response is received, I display this list in the user interface using ng-repeat. So far so good, but I want to automatically focus on the element that matters itemId, which allows you to say 50 when the page loads. I want this from the controller side.
Below is the code that I have.
HTML
<div id="eventTypes" class="panel-body">
<div ng-repeat="item in items" class="panel-body">
<div class="row">
<div class="col-md-9">{{item.itemId)}}</div>
<div class="col-md-9">{{item.itemName)}}</div>
<div class="col-md-9">{{item.isAvailable)}}</div>
</div>
</div>
</div>
Js
(function () {
'use strict';
angular.module('myApp').controller('itemsController', function ($scope, itemsService) {
var serviceError = function (errorMsg) {
console.log(errorMsg);
};
$scope.items = [];
$scope.loaditems = function () {
itemsService.getitems().then(function (response) {
$scope.items = response.data;
}, serviceError);
};
$scope.loaditems();
});
}());
. . () 50 .