日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁 > 芯聞號 > 充電吧
[導(dǎo)讀]Material 提供了大量的android 風(fēng)格的UI組件,使用 angularjs + Material 可以很容易開發(fā)出風(fēng)格接近原生 Android 5.x 的web界面。但在實際使用的過程中并

Material 提供了大量的android 風(fēng)格的UI組件,使用 angularjs + Material 可以很容易開發(fā)出風(fēng)格接近原生 Android 5.x 的web界面。但在實際使用的過程中并不總是能滿足我們的需求。開發(fā)一個組件就成了我們必須學(xué)習(xí)的內(nèi)容。


下面是一個組件的實現(xiàn):


//前面省略若干代碼
directive('mdSearchInput',[function(){

????return{
????????restrict:'E',
????????controller:['$scope','$timeout',function($scope,$timeout){
????????????var?tsk=null;
????????????$scope.delay=1000;
????????????$scope.on_changed=function(){
????????????????if(null?!==?tsk)?{$timeout.cancel(tsk);}?//去掉前一個任務(wù)
????????????????tsk?=?$timeout(function(){
????????????????????$timeout.cancel(tsk);tsk=null;
???????????????????$scope.onSearch()($scope.searchText);
????????????????},$scope.delay);
????????????};$scope.on_clear=function(){
????????????????var?tsk=null;$scope.searchText='';
????????????????tsk=$timeout(function(){
????????????????????$timeout.cancel(tsk);tsk=null;
????????????????????$scope.onSearch()($scope.searchText);
????????????????},100);
????????????}

????????}],
????????scope:{
????????????inputName:??????'@mdInputName',
????????????searchText:?????'=?mdSearchText',
????????????onSearch:???????'&?mdSearch',
????????????placeholder:????'@placeholder',
????????????delay:????????????'@delay'
????????},
????????template:'\',
????????link:function($scope,?$element){

????????}
????};
}]);


CSS 樣式:



.md-search-input{
??box-sizing:?border-box;border:?none;box-shadow:?none;background:?0?0;?border-radius:5px;background:?#FFF;margin:0px;position:?relative;
??input{outline:?0;font-size:?14px;?width:?100%;?padding:?0?15px;?line-height:?40px;height:?40px;border:?none;background:transparent;}
??button,.md-fab,.md-button,button:hover,.md-fab:hover?{
????background:transparent?!important;
????line-height:40px;height:40px;width:40px;font-size:14px;box-shadow:none?!important;margin:0px;padding:0px;
????color:rgba(0,0,0,0.5)?!important;
??}
}


配合 ng-route 可以很容易實現(xiàn)無刷新的APP 讓您的web頁面更加接近app體驗,


在 maincontroll中,通過監(jiān)聽 ng-route 的頁面即將跳轉(zhuǎn)事件 來重置消息框,


?//在頁面改變之前,重置搜索框.
????$scope.$on('SearchText.Reset',function(){?$scope.searchConfig={show:false,?key:'',delay:1200};});
????$rootScope.$on('$routeChangeStart',?function?(event,?next)?{
????????$rootScope.$broadcast('SearchText.Reset');
????});




而在需要用到搜索功能的地方,則只需要在控制器里通過如下代碼實現(xiàn):



?//陪值搜索框為己用
????$scope.$emit('Search.Config',{
????????show:true,?key:'',delay:800,
????????emptyText:"請輸入:商家名稱,賬號,電話?等內(nèi)容以進(jìn)行搜索.",
????????onSearch:?function(){
????????????return?function(v){
????????????????$scope.merData.query(v);?//調(diào)用本控制器的數(shù)據(jù)查詢接口.
????????????}
????????}
????});


本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉