angular-material 是 AngularJS 的一个子项目,用来提供实现了 Material Design 风格的组件。
Material 提供了大量的android 风格的UI组件,使用 angularjs + Material 可以很容易开发出风格接近原生 Android 5.x 的web界面。但在实际使用的过程中并不总是能满足我们的需求。开发一个组件就成了我们必须学习的内容。
下面是一个组件的实现:
//前面省略若干代码 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);} //去掉前一个任务 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: '="md-search-input" layout="row">\ <input type="text" flex autocomplete="off" ng-model="searchText" name="{{inputName}}" placeholder="{{placeholder}}" ng-change="on_changed()" />\ <md-button class="md-fab" ng-click="on_clear()" ng-show="searchText!==\'\'"><md-icon md-svg-icon="md-close" style="color:rgba(0,0,0,0.5);"></md-icon></md-button>\ </div>', 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 可以很容易实现无刷新的APP 让您的web页面更加接近app体验,
在 maincontroll中,通过监听 ng-route 的页面即将跳转事件 来重置消息框,
//在页面改变之前,重置搜索框. $scope.$on('SearchText.Reset',function(){ $scope.searchConfig={show:false, key:'',delay:1200};}); $rootScope.$on('$routeChangeStart', function (event, next) { $rootScope.$broadcast('SearchText.Reset'); });
而在需要用到搜索功能的地方,则只需要在控制器里通过如下代码实现:
//陪值搜索框为己用 $scope.$emit('Search.Config',{ show:true, key:'',delay:800, emptyText:"请输入:商家名称,账号,电话 等内容以进行搜索.", onSearch: function(){ return function(v){ $scope.merData.query(v); //调用本控制器的数据查询接口. } } });
以上所述是小编给大家介绍的Angularjs material 实现搜索框功能,希望对大家有所帮助!
风云阁资源网 Design By www.bgabc.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
风云阁资源网 Design By www.bgabc.com
暂无评论...
更新日志
2024年09月23日
2024年09月23日
- 王子异《1996 Part.2》[320K/MP3][18.29MB]
- 群星.1994-宝丽金最倾情3CD【宝丽金】【WAV+CUE】
- 乐俊亨.2024-同泪【CharioticMusic】【FLAC分轨】
- 何耀珊.2006-收获【华纳】【WAV+CUE】
- 梁汉文1994-壹精选[华星][WAV+CUE]
- 洪荣宏1981-歹路不可行·相思雨(飞跃复刻版)[光美][WAV+CUE]
- 旅行团2015-10Day’s[来福胶泥][WAV+CUE]
- 龙千玉.2011-卡将哟【豪记】【WAV+CUE】
- 蔣志光.1993-多情多寂寞(国专)【BMG】【WAV+CUE】
- 陈慧娴.1996-雪映美白96演唱会2CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 王子异《1996 Part.2》[FLAC/分轨][50.66MB]
- 贵族音乐《古典名曲与轻音乐钢琴 打开宝宝睡眠开关》[320K/MP3][155.91MB]
- 贵族音乐《古典名曲与轻音乐钢琴 打开宝宝睡眠开关》[FLAC/分轨][251.78MB]
- 黄韵玲2001-巴结音乐[全员集合][WAV+CUE]
- 郑绪岚2015-流金岁月·精选[首版][WAV+CUE]