ホスティング Ctrl:
function HostingListCtrl($scope, Hosting) {
Hosting.all().success(function(data) {
$scope.hostings = data;
});
}
HTML テンプレート:
<pagination items-count="{{hostings.length}}" current-page="currentPage" items-per-page="{{itemsPerPage}}"></pagination>
指令:
admin.directive('pagination', function() {
return {
restrict: 'E',
replace: true,
templateUrl: "<%= asset_path('angular/templates/ui/pagination.html') %>",
scope: {
currentPage: '=',
itemsCount: '@',
itemsPerPage: '@'
},
controller: function($scope, $element, $attrs) {
console.log($scope);
console.log($scope.itemsCount);
},
link: function(scope, element, attrs, controller) {
}
};
});
ディレクティブで itemsCount 変数の値を取得しようとしていますが、console.log にしようとすると値が空になります。奇妙なことは、console.log のスコープ全体が存在することです。
Scope {$id: "005", $$childTail: null, $$childHead: null, $$prevSibling: null,
$$nextSibling: null…}
$$asyncQueue: Array[0]
$$childHead: null
$$childTail: null
$$destroyed: false
$$isolateBindings: Object
$$listeners: Object
$$nextSibling: Child
$$phase: null
$$prevSibling: null
$$watchers: Array[3]
$id: "005"
$parent: Child
$root: Scope
currentPage: 1
itemsCount: "11"
itemsPerPage: "5"
this: Scope
__proto__: Object
また、HTMLソースを確認すると
<nav class="pagination" items-count="11" current-page="currentPage" items-per-page="5">