Angular --- 自定义指令更新
来源:互联网 发布:肖雪萍 知乎 编辑:程序博客网 时间:2024/05/16 15:25
1.左滑删除
<li ng-repeat="name in names" drag-to-dismiss="deleteTodo($index)" >……</li>app.directive('dragToDismiss', function($drag, $parse, $timeout) { return { restrict: 'A', compile: function(elem, attrs) { var dismissFn = $parse(attrs.dragToDismiss); return function(scope, elem) { var dismiss = false; $drag.bind(elem, { transform: $drag.TRANSLATE_LEFT, move: function(drag) { if ( Math.abs(drag.distanceX) >= drag.rect.width / 4) { dismiss = true; elem.addClass('dismiss'); } else { dismiss = false; elem.removeClass('dismiss'); } }, cancel: function() { elem.removeClass('dismiss'); }, end: function(drag) { if (dismiss) { elem.addClass('dismitted'); $timeout(function() { scope.$apply(function() { dismissFn(scope); }); }, 300); } else { drag.reset(); } } }); }; } };});
2.Jquery slideToggle()指令
<div ng-controller="slideController"> <li ng-repeat-start="todo in todos" ng-click="$index=!$index">{{todo.name}}</li> <li ng-repeat-end slide-toggle="$index">{{$index}}</li></div>//控制器app.controller('slideController', function ($scope) {$scope.todos=[{name:'1'},{name:'2'},{name:'3'},{name:'4'}]});//指令app.directive('slideToggle', function() {return {restrict: 'A',scope:{isOpen: "=slideToggle"},link: function(scope, element, attr) {scope.$watch('isOpen', function(newVal,oldVal){if(newVal !== oldVal){element.stop().slideToggle('slow');}});}};});
<input ng-model="editArea"/>$scope.Rewrite = function (e) {$scope.$watch('editArea', function(newValue, oldValue) {if (newValue !== oldValue) { return } // AKA first run$scope.editArea = $scope.mes[e].Message});}
4.多维嵌套
<div ng-app> <div ng-controller="test"> <div ng-repeat="links in slides"> <hr/> <div ng-repeat="link in links track by $index"> {{link}} </div> </div> </div></div>function test($scope) { $scope.slides = [ [ 1, 1, 1 ], [ 4, 5, 6 ], ];}
0 0
- Angular --- 自定义指令更新
- angular 自定义指令
- angular js自定义指令
- Angular自定义指令(进阶)
- angular自定义指令
- 创建angular自定义指令
- angular 自定义指令
- angular自定义指令templateUrl
- Angular 自定义指令详解
- 一,Angular自定义指令
- Angular自定义指令
- angular自定义指令详解
- angular自定义指令
- angular.js自定义指令
- angular 自定义指令命名
- angular指令和自定义指令
- angular 自定义指令参数详解
- Angular自定义指令(初级)
- struts2和springmvc的区别
- df、du、fdisk:Linux磁盘管理三板斧的使用心得
- Android 退出应用几种方式
- adb shell top 查看内存和cpu
- hdu2824The Euler function(打表)
- Angular --- 自定义指令更新
- 设计模式C++实现(1)——工厂模式
- matlab中传递函数的离散化
- Springmvc 工作机制源码分析
- 超小股票行情查看软件
- 05-Java常用类库
- Fresco
- startUML破解
- 全排列