Hi All, I am new to angular js and doing some random stuff. I am sharing the code here. Hope this will help you some where.
<style>
table, td {
border: 1px solid grey;
border-collapse: collapse;
padding: 5px;
}
.sortorder:after {
content: '\25b2';
}
.sortorder.reverse:after {
content: '\25bc';
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="customersCtrl">
<table>
<tr>
<td ng-click="order('Name')">
Customer Name
<span class="sortorder" ng-show="predicate === 'Name'" ng-class="{reverse:reverse}"></span>
</td>
<td ng-click="order('City')">
City
<span class="sortorder" ng-show="predicate === 'City'" ng-class="{reverse:reverse}"></span>
</td>
<td ng-click="order('Country')">
Country
<span class="sortorder" ng-show="predicate === 'Country'" ng-class="{reverse:reverse}"></span>
</td>
</tr>
<tr>
<td><input type="text" ng-model="name"></td>
<td><input type="text" ng-model="city"></td>
<td><input type="text" ng-model="country"></td>
</tr>
<tr ng-repeat="x in names | filter:name | filter:city | filter:country | orderBy: predicate:reverse">
<td>
{{ x.Name }}
</td>
<td>
{{ x.City }}
</td>
<td>
{{ x.Country }}
</td>
</tr>
<br/>
</table>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
// SORTS
$scope.reverse = true;
$scope.order = function(predicate) {
$scope.reverse = !$scope.reverse;
$scope.predicate = predicate;
};
$http.get("http://www.w3schools.com/angular/customers.php")
.then(function (response) {
$scope.names = response.data.records;
});
});
</script>
Output
Nice article Mohit !! Keep it up.
ReplyDeleteThanks :) Angular is a great benefit for developers and designers both
Delete