Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var app = angular.module('main', ['ngTable']);
- app.controller('MyCtrl', function($scope, $resource, $http, ngTableParams) {
- var data = [];
- $scope.tableParams = new ngTableParams({
- page: 1,
- count: 10
- }, {
- total: data.length,
- getData: function($defer, params) {
- $http({method:'GET', url:'/'}).then(function successCallback(response)
- {
- data = response.data;
- });
- $scope.news = data.slice((params.page() - 1) * params.count(), params.page() * params.count());
- $defer.resolve($scope.news);
- }
- });
- $scope.getAllNews = function(){
- $http.get('/').success(function(response){
- $scope.news = response.data;
- }).error(function() {
- });
- }
- });
- @RequestMapping("/")
- public String list (Model model) {
- log.info("Listing news...");
- List<News> news = newsService.findAll();
- model.addAttribute("news", news);
- log.info(news.size() + " news have founded");
- return "news/list";
- }
- <div id="demo" ng-controller="MyCtrl">
- <table ng-table="tableParams" class="table">
- <tr ng-repeat="itm in news">
- <td data-title="'Date'">
- {{itm.date}}
- </td>
- <td data-title="'Text'">
- <div>{{itm.head}}</div>
- <div>{{itm.body}}</div>
- </td>
- </tr>
- </table>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement