Deleting a confirmation box with a custom directive implementation in angular

Source: Internet
Author: User

My deletion, you can delete a task individually, or you can delete it by category (category and task collection that belongs to this category).

First page

task.ng.html

   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"  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 is this controller scope object, and scope inherits the parent scope object thereby creating a new action object that can access methods and properties in the parent class
$scope. determine = function (obj) {
scope. OK (obj); Run the parent controller method
$modalConfirmInstance. Close (true);
};

$scope. Cancel = function () {
$modalConfirmInstance. Dismiss (' Cancel ');
};
}],
size: ' MD '

});

});
}
}
}])


Deleting a confirmation box with a custom directive implementation in angular

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.