angularjs使用directive實(shí)現(xiàn)分頁(yè)組件的示例
閑來(lái)沒(méi)事,分享下項(xiàng)目中自己寫(xiě)的分頁(yè)組件。來(lái)不及了,直接上車(chē)。
效果:



輸入框可任意輸入,并會(huì)自動(dòng)提交到該頁(yè)
依賴(lài)項(xiàng):
fontawesome,bootstrap
html:
<ul class="page clearfix">
<li ng-hide="currentPage <= 1">
<a href="" ng-click=" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" firstPage()">
<i class="fa fa-step-backward"></i>
</a>
<a href="" ng-click=" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" prePage()">
<i class="fa fa-play fa-flip-horizontal"></i>
</a>
</li>
<li>
<span>頁(yè)碼</span>
<input type="text" ng-model="currentPage">/
<span ng-bind="totalPage"></span>
</li>
<li ng-hide="currentPage >= totalPage">
<a href="" ng-click=" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" nextPage()">
<i class="fa fa-play"></i>
</a>
<a href="" ng-click=" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" lastPage()">
<i class="fa fa-step-forward"></i>
</a>
</li>
</ul>
css:
/* 分頁(yè) */
.page {
margin: 15px 0;
padding: 0;
float: right;
}
.page li {
list-style: none;
float: left;
height: 30px;
line-height: 30px;
}
.page li input {
padding: 3px 5px;
height: 100%;
width: 50px;
border: none;
background-color: #EAEEF1;
text-align: center;
margin-right: 10px;
}
.page li span {
margin-right: 15px;
}
.page li a {
text-decoration: none;
outline: none;
margin-right: 15px;
}
directive:
App.directive('paging', function() { // 分頁(yè)
return {
restrict: 'A',
replace: true,
scope: {
totalPage: '=totalPage',
currentPage: '=currentPage',
getData: '&getData'
},
templateUrl: 'app/views/partials/paging.html',
controller: function($scope) {
$scope.firstPage = function() { $scope.currentPage = 1; }
$scope.lastPage = function() { $scope.currentPage = $scope.totalPage; }
$scope.prePage = function() { $scope.currentPage--; }
$scope.nextPage = function() { $scope.currentPage++; }
$scope.$watch('currentPage', function(newVal, oldVal) {
if(newVal != oldVal && newVal) $scope.getData();
})
}
};
});
參數(shù):
- totalPage: 總頁(yè)數(shù),
- currentPage: 當(dāng)前頁(yè),
- getData: 點(diǎn)擊分頁(yè)所觸發(fā)的函數(shù)
用法:
controller:
$scope.current_page = 1; // 當(dāng)前頁(yè)
$scope.getData = function() {
$scope.param.page = $scope.current_page;
ConnectApi.start('post', 'index/student/getschoolclasslist', $scope.param).then(function(response) { // 這個(gè)ConnectApi 你大可不必關(guān)心,這是我封裝的http函數(shù)
var data = ConnectApi.data({ res: response, _index: index });
$scope.data = data.data;
$scope.totalpage = data.data.total_page; // 服務(wù)器端返回的總頁(yè)數(shù)
}
}
$scope.getData(); // 獲取數(shù)據(jù)的函數(shù)
html:
<div paging total-page="totalpage" current-page="current_page" get-data="getData()"></div>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Vue.js分頁(yè)組件實(shí)現(xiàn):diVuePagination的使用詳解
- vuejs2.0實(shí)現(xiàn)分頁(yè)組件使用$emit進(jìn)行事件監(jiān)聽(tīng)數(shù)據(jù)傳遞的方法
- Reactjs實(shí)現(xiàn)通用分頁(yè)組件的實(shí)例代碼
- 原生js編寫(xiě)基于面向?qū)ο蟮姆猪?yè)組件
- Vue.js實(shí)現(xiàn)一個(gè)自定義分頁(yè)組件vue-paginaiton
- 使用vue.js制作分頁(yè)組件
- 基于Vue.js的表格分頁(yè)組件
- js多功能分頁(yè)組件layPage使用方法詳解
- 分享一個(gè)自己寫(xiě)的簡(jiǎn)單的javascript分頁(yè)組件
- JavaScript分頁(yè)組件使用方法詳解
相關(guān)文章
Angular5.0 子組件通過(guò)service傳遞值給父組件的方法
這篇文章主要介紹了Angular5.0 子組件通過(guò)service傳遞值給父組件的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-07-07
簡(jiǎn)介AngularJS的視圖功能應(yīng)用
這篇文章主要介紹了AngularJS的視圖功能應(yīng)用,包括ng-view和ng-template以及$routeProvider的使用,以及 $routeProvider 需要的朋友可以參考下2015-06-06
Angular.js中下拉框?qū)崿F(xiàn)渲染html的方法
這篇文章主要給大家介紹了關(guān)于在Angular.js中下拉框?qū)崿F(xiàn)渲染html的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)跟著小編一起來(lái)學(xué)習(xí)學(xué)習(xí)吧。2017-06-06
AngularJS頁(yè)面訪問(wèn)時(shí)出現(xiàn)頁(yè)面閃爍問(wèn)題的解決
這篇文章主要介紹了AngularJS框架使用中出現(xiàn)頁(yè)面閃爍問(wèn)題的解決方法,閃爍問(wèn)題一般是初始化未加載完畢造成的,需要的朋友可以參考下2016-03-03
AngularJs 延時(shí)器、計(jì)時(shí)器實(shí)例代碼
這篇文章主要介紹了AngularJs 延時(shí)器、計(jì)時(shí)器實(shí)例代碼,需要的朋友可以參考下2017-09-09

