first I will show you my html:
<div class="pager" pager-control getPageNumber="getPageNumber()" getPageData="getPageData()">
my purpose of this "directive" is making pager. and this is the js file blew:
var paging = angular.module('paging',[]);
paging.controller('pageCtrl',function($scope,$timeout){
$scope.currentPageIndex = 0;
$scope.model = [
{ name: 'www'},
{ name: 'www'},
{ name: 'www'},
{ name: 'www'},
{ name: 'www'}
];
$scope.getPageNumber = function(){
var len = 10,ret=[];
for(i = 0;i < 10; i++) {
ret.push(i);
}
return ret;
};
$scope.getPageData = function(index) {
$scope.currentPageIndex = index;
alert('trigger!');
};
});
paging.directive('pagerControl',function(){
return {
restict: 'A',
replace: false,
transclude: true,
template: '<ul ng-transclude><li ng-class="{current: $parent.currentPageIndex == $index}" ng-repeat="d in $parent.getPageNumber()" ng-click="$parent.getPageData($index)">{{$index + 1}}</li> </ul>',
scope: {
},
link: function(scope,elem,attr) {
}
};
});
expect to "when you click the page item,the color will change ",but nothing happends..
this is the jsbin url:
http://jsbin.com/vijax/2/edit