Giorgi Goginashvili Giorgi Goginashvili - 1 year ago 97
AngularJS Question

How to pass dir-paginate item to angular function

I have select tag in html

<select id="selectTerminalGroups" ng-model="selectedGroup" ng-change="showSelected(x)">
<option dir-paginate="x in serverData | itemsPerPage: serverData.length" value='{{ x.id }}'>{{ x.name }}</option>
<input class="getItems" name="Submit" type="submit" value="Renew" ng-click="showSelected(x)"/>
</select>


and here is my
showSelected(x)
function

$scope.showSelected = function(item)
{
console.log(item);
}


in angular function my x('item' in angular) is undefined.I want to take this x object in angular

Answer Source

Change showSelected(x) to showSelected(selectedGroup). ng-modal track's current element value..

Edit There is a working Example try this.

var app = angular.module("app",[]);
app.controller("ctrl", function($scope){

$scope.data = [{name:'test1'},{name:'test2'},{name:'test3'}];
$scope.selectedItem = $scope.data[0];
$scope.change = function( item )
{
  console.log(item)
}

})
<html>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  </head>
  <body  ng-app="app" ng-controller="ctrl" >
  <select ng-model="selectedItem" ng-change="change(selectedItem)" >
    <option ng-repeat="item in data" > {{item.name}} </option>
    <input name="Submit"  type="submit" value="Renew" ng-click="change(selectedItem)">
  </select>
  </body>
</html>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download