【发布时间】:2014-01-27 05:23:58
【问题描述】:
我正在尝试编写一个分页器作为我的应用程序的指令,但我似乎无法让它工作。我看过的每个地方都建议使用$compile,但我根本无法让它工作。
这是我的,你可以观看现场演示here
var app = angular.module('myApp', []);
app.controller('MyController', function($scope) {
$scope.items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
});
app.directive('myPaginator', function() {
return {
restrict : 'A',
priority : 1000,
scope : {
items : '=myPaginator'
},
controller : function($scope) {
$scope.amount = 5;
}
};
});
app.directive('myPaginatorItem', function($compile) {
return {
restrict : 'A',
require : '^myPaginator',
priority : 999,
compile : function(element) {
element
.removeAttr('my-paginator-item')
.attr('ng-repeat', 'item in items | limitTo:amount');
return function($scope, element) {
$compile(element)($scope);
}
}
};
});
您可能会说,我对 Angular 还是很陌生,任何帮助都将不胜感激。
【问题讨论】:
标签: javascript angularjs angularjs-directive angularjs-scope angularjs-ng-repeat