angularjs の pager ディレクティブに取り組んでいます。サンプル コレクション ($scope.installations) をハード コーディングするとすべて問題ありませんが、サーバーからデータをプルすると、ディレクティブの「オプション」プロパティが常に「未定義」になります。
これが私の指示です:
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 ???
});
}
};
}
]);
これが私がそれを呼んでいる方法です。
<ul qn:pager="{source: installations}">
そして最後に私のコントローラーサンプル
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;
});
}