-
-
Save orlybg/1531df6684f814f9a6f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var MyController, MyService, | |
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; | |
MyController = (function() { | |
function MyController($scope, service, $q, ngTableParams, $filter) { | |
this.$scope = $scope; | |
this.service = service; | |
this.service.$scope = $scope; | |
this.service.$q = $q; | |
this.$q = $q; | |
this.ngTableParams = ngTableParams; | |
this.$filter = $filter; | |
console.log('filter in constructor: ', $filter); | |
this.initializeData = __bind(this.initializeData, this); | |
this.service.fetchDataFromServer().then(this.initializeData); | |
// more project logic | |
} | |
MyController.prototype.initializeData = function(data) { | |
console.log('filter in initialize: ', this.$filter ); | |
// project data init | |
this.$scope.tableParams = new this.ngTableParams({ | |
page: 1, // show first page | |
count: 10, // count per page | |
sorting: { | |
name: 'id' // initial sorting | |
} | |
}, { | |
total: this.pools.length, // length of data | |
getData: this.getData(this.$q, params) | |
}); | |
return this.loading = false; | |
}; | |
MyController.prototype.getData = function($defer, params) { | |
console.log('getData params: ', params); | |
console.log('getData defer: ', $defer); | |
console.log('getData filter: ', this.$filter); | |
/* | |
// use build-in angular filter | |
var orderedData = params.sorting() ? | |
this.$filter('orderBy')(this.pools, params.orderBy()) : | |
this.pools; | |
$defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count())); | |
*/ | |
}; | |
// more project methods | |
return MMyearchController; | |
})(); | |
// The myService | |
angular.module('module-name', ['ngTable']) | |
.constant('settings-conf', { | |
// bunch of API URL's | |
}) | |
.service('MyService', ['$http', 'settings-conf', MyService]) | |
.controller('MyCtrl', ['$scope', 'MyService', '$q', 'ngTableParams', '$filter', MyController]) | |
.directive('moneyPoolSearch', function() { /*directive settings */}); | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment