比如有四个列表,布局几乎一样,只有细微的区别,Controller的代码自然也就非常类似了,比如只有请求参数不同。
initialize();
$scope.refreshHub[$scope.REFRESH_METHOD[$scope.nowIndex]] = function () {
$scope.model_request.pageNum = 1;
business_XW1.requestNewsList($scope.model_request).then(
function (okRs) {
$scope.list = okRs.response.parram;
setTimeout(function () {
$rootScope.loadMoreState = $scope.list.length >= $scope.model_request.pageSize;
},500);
},$scope.errorCallback
).always(function () {
$rootScope.$broadcast('scroll.refreshComplete');
});
};
$scope.loadHub[$scope.LOAD_METHOD[$scope.nowIndex]] = function () {
$scope.model_request.pageNum++;
business_XW1.requestNewsList($scope.model_request).then(
function (okRs) {
Array.prototype.push.apply($scope.list,okRs.response.parram);
$rootScope.loadMoreState = okRs.response.total > $scope.list.length;
},$scope.errorCallback
).always(function () {
$rootScope.$broadcast('scroll.infiniteScrollComplete');
});
};
// helper methods ~
function initialize() {
$scope.model_request = new xw_model.Corporation();
$scope.list = [];
}
比如这段代码,这四个列表的Controller中,只有model_request参数不同,那么我该如何才能复用这段代码呢?
http://stackoverflow.com/questions/16539999/whats-the-recommended-way-to-extend-angularjs-controllers