Sunday, 8 May 2016

Call API in AngularJS, Data Show using ng-repeat and and global filter

In Angular JS ng-repeat directives use for collection show in table. $http service use for to call API.

Ex.

<!DOCTYPE html>
<html>
<body>

<div ng-app="myApp" ng-controller="customersCtrl"> 

<p><input type="text" ng-model="test"></p>

<table>
<tr><th  ng-click="orderByMe('name')">Company Name</th><th ng-click="orderByMe('country')">Price</th><th>Price Difference</th><th>Date</th></tr>
  <tr ng-repeat="x in MyData | filter : test">
    <td>{{ x.co_name }}</td>
    <td>{{ x.price }}</td>
 <td>{{ x.price_diff }}</td>
    <td>{{ x.tr_date }}</td>
  </tr>
</table>

</div>

<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {


//alert(JSON.stringify(response.data.response.data));
$scope.MyData = response.data.response.data.companylist.company;});
});
</script>

</body>
</html>

No comments:

Post a Comment