Working on pager directive in angularjs. When I hard code sample collection ($scope.installations) everything is OK, but when I pull data from server 'options' property in directive is always 'undefined'.
Here is my directive:
angular.module("qusion.ui.pager", [])
.directive("qnPager", [
function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
var options = scope.$eval(attrs.qnPager);
var settings = {
source: null,
paging: null,
schema: {
page: 'PageNumber',
size: 'Size',
totalPages: 'TotalPages',
totalCount: 'TotalCount'
}
};
angular.extend(settings, options);
scope.$watch(settings.source, function(value) {
console.log(settings.source); // UNDEFINED ???
});
}
};
}
]);
Here is how I am calling it.
<ul qn:pager="{source: installations}">
And finally my controller sample
function MyController(Installation){
$scope.installations = [];
// get sample (this works)
// $scope.installations = [{ID: 1, Title: 'Test 1'}, {ID: 2, Title: 'Test 2'}]
// get from server (this don't work)
Installation.getAll().then(function(data) {
$scope.installations = data.Installations;
});
}