使用angular中自定义的directive实现删除确认框

我的删除情况,可单独删除一条任务,也可以根据类别删除(类别和所属此类别的任务集合)。

首先页面

task.ng.html

   <span ng-click="remove(task)" confirm><span class="glyphicon glyphicon-trash icon" ></span></span>

TaskController
$scope.ok = function (task) {    $scope.tasks.remove(task);};

Type.ng.html
<span class="glyphicon glyphicon-trash typeedit"  ng-if="type.showIcon" confirm style="margin-right: 5px;z-index: 5;">
TypeController
$scope.ok = function(type){
   /*removetasksService is inject service */
    removetasksService.removetasksbyType(type._id);  
    $scope.types.remove(type);};
 
directive.js:
angular.module(‘demoOne‘).directive(‘confirm‘,[‘$modal‘,function($modal) {

    return {        restrict: ‘A‘,        scope:true,        link:function(scope, element, attrs){

            element.bind("click", function() {               //ConfirmService.open(attrs.confirm);                var modalConfirmInstance = $modal.open({                    templateUrl: ‘client/tasks/views/myDeleteConfirm.ng.html‘,                    controller:[‘$scope‘,‘$modalInstance‘, function($scope,$modalConfirmInstance){

                        //get obj from parent Controller                        if(scope.task!=null){                            $scope.obj = scope.task;                        }else{                            $scope.obj = scope.type;                        }
$scope 是此控制器作用域对象 ,而 scope是继承了父作用域对象从而创建一个新的作用于对象,可以访问父类中的方法和属性
                        $scope.determine = function (obj) {                            scope.ok(obj);   //run the parent controller method                            $modalConfirmInstance.close(true);                        };

                        $scope.cancel = function () {                            $modalConfirmInstance.dismiss(‘cancel‘);                        };                    }],                    size:‘md‘

                });

            });        }    }}])
				
时间: 2024-08-27 11:09:07

使用angular中自定义的directive实现删除确认框的相关文章

LinkButton中添加删除确认框

LinkButton1.Attributes.Add("onclick", "javascript:return confirml('确认删除?');"); LinkButton中添加删除确认框

angular中自定义依赖注入的方法和decorator修饰

自定义依赖注入的方法 1.factory('name',function () { return function(){ } }); 2.provider('name',function(){ this.$get=function(){ return function(){ } }; }); 3.service('name',function(){ this.n=v; }); 4.constant('name','value'); 5value('name','value'); 依赖的继承  

javascript中输出信息的方法-信息确认框-提示输入框-文档流输出

js中输出信息的方法 1.文档流输出 document.write('hello'); 2.输出信息提示框 模态对话框 window.alert('要输出显示的内容');  或 alert('要输出显示的内容'); alert(n); 3.信息确认框 var f =  window.confirm('是否要进入新浪网');  confirm(""); if(f){ location.href = 'http://www.sina.com.cn'; } 4.提示输入框 window.pr

-_-#【Angular】自定义指令directive

AngularJS学习笔记 <!DOCTYPE html> <html ng-app="Demo"> <head> <meta charset="utf-8"> <title></title> </head> <body> <script src="jquery-1.8.3.min.js"></script> <scrip

swal() 弹出删除确认框

//删除 function del() { var id = ""; var row = $.map($("#DataList").bootstrapTable('getSelections'), function (row) { id = row.Id; return row; }); if (row == null || row.length <= 0) { swal("提示信息", "请选择要删除的记录!", Ic

angular中transclude的理解

今天被这个transclude搞糊涂了,弄了半天,才知道原来使用起来很简单.很烦恼为社么书中的对于这个的介绍这么晦涩难懂.直到看到了这篇文章,才让我弄清楚了. 一.transclude介绍 transclude是angular中自定义指令中的一个参数.中文就是嵌入的意思.也就是说通过这个参数设置,可以将指令内容嵌入到自定义指令中的模版中.其值默认是false,当为true时,会起到嵌入的作用. 二.使用 首先我们先看一下不使用tranclude的情况: js: app.directive('my

javaScript 删除确认实现方法总结分享

第一种方法:挺好用的,确认以后才能打开下载地址页面.原理也比较清晰.主要用于删除单条信息确认.<SCRIPT LANGUAGE=javascript> function p_del() { var msg = "您真的确定要删除吗?\n\n请确认!"; if (confirm(msg)==true){ return true; }else{ return false; } } </SCRIPT> 调用方法: <a href="del.jsp?id

Angular中的内置指令和自定义指令

NG中的指令,到底是什么(what)? 为什么会有(why)?以及怎样使用(how)? What: 在NG中,指令扩展HTML功能,为 DOM 元素调用方法.定义行为绑定数据等. Why: 最大程度减少DOM操作,实现数据绑定,与业务逻辑进行交互. How: 指令主要分为两种:内置指令和自定义指令,通过下面的例子,简单记录一下如何去使用. 内置指令 在官方API文档上罗列了很多指令,内置指令可以分为:普通指令 和 事件指令,他们都是作用于HTML之上的,通过添加属性的方式来实现的.简单看一下一些

angular 自定义指令 directive transclude 理解

项目中断断续续的用了下angular,也没狠下心 认真的学习.angular 特别是自定义指令这块 空白. transclude 定义是否将当前元素的内容转移到模板中.看解释有点抽象. 看解释有点抽象Demo: <!DOCTYPE html> <html lang="en" ng-app='myApp'> <head> <meta charset="UTF-8"> <title>Angularjs</