我正在尝试编写我的第一个Angular指令来为我的应用程序添加分页功能。 我现在保持简单,并希望指令只是分享控制器的范围。简单的角度指令
在我的控制,我有一个名为范围的变种:
$scope.pages
在我的指导的链接功能,我可以这样做:
console.dir($scope)
看到控制器的范围对象的内容,但如果我尝试访问pages属性,则返回为undefined。
我错过了什么?
在此先感谢。
myDirectives.directive("mdPagination", function(){
return {
template: '',
restrict: 'A',
priority: 1000,
scope: false,
link: function($scope, el, attrs){
console.dir($scope.pages); //returns undefined
el.text('hello world');
},
}
});
编辑:我知道有分页模块在那里,但我的需求是温和的,我想建设自己将开始学习如何建立指令的简单方法。
尝试删除'scope:false' – akonsu
$ scope.pages是如何在你的控制器中填充的?通过AJAX请求? –
查看这些现有的AngularJS分页模块@ http://ngmodules.org/modules?query=pagination –