0

In Angular How Do I Automatically select last row in a table and invoke function

html

ng-repeat="order in orders | filter: prop.value |orderBy:orderByField:reverseSort | limitTo:-3" ng-click="selectOrder(order); setSelected()" class={{selected}}

controller

$scope.setSelected = function() {
    console.log("show", arguments, this);
    if ($scope.lastSelected) {
        $scope.lastSelected.selected = '';
     }
     this.selected = 'selected';
     $scope.lastSelected = this;
}

$scope.selectOrder = function (order) {
    $scope.selectedOrder = order;
};

This html returns a list of three orders in a list when I click on a row in the list it displays an additional table with the items in an order perfectly

Without clicking on an order no additional table is displayed which is undesirable

Objective: I want it to automatically select and click the last row so additional items in an order is always displayed on screen

Vi100
  • 4,080
  • 1
  • 27
  • 42
user3265817
  • 99
  • 1
  • 13

2 Answers2

1

You could add a callBack when the last row is generated, and include there the call to your function. There are lots of examples that you can find in internet (for instance, this one ng-repeat finish event)

Community
  • 1
  • 1
Rumoroso
  • 154
  • 4
0

for my example this worked and auto selected and invoked the function

ng-init=" $last && selectOrder(order); setSelected()" class={{selected}}>>

user3265817
  • 99
  • 1
  • 13