主机控制:
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">