指令:
//自定義加載框
App.register.directive('loadmore', function() {
return {
restrict: 'E',
replace: true,
template: "<button style='width:50%;border:1px solid #d7d7d7;background:white;color:#22bbf5;margin:6px 25% 0 25%;' id='fat-btn' data-loading-text='載入中...'' class='btn' ng-click='loadmore()'>加載更多數(shù)據(jù)</button>",
link: function(scope, element, attrs, controller) {
var method = attrs["method"];
var model = attrs["model"];
//默認十行一次分頁
scope.loadmore = function() {
scope.loadresults = scope[model];
console.log(scope.loadresults);
scope.num++;
scope[method](10, scope.num, function(data) {
if (data != null) {
scope.loadresults = scope.loadresults.concat(data);
scope.$apply();
console.log(scope.loadresults);
scope[model] = scope.loadresults;
}
});
}
}
}
});
使用方式:
使用效果: