Hey there, I've developed a custom directive that handles delete functionality across all screens. After deleting elements, I need to call a controller function to update the view. Keep in mind that the controller may vary based on the specific view.
angular.module('app.comon').directive('deletePopup', function modal(setterGetterService,restCallService) {
return {
template:'<div class="modal" id="delete-popup">' +
'<div class="modal-dialog">' +
'<div class="modal-content">' +
'<p>Are you sure you want to delete?</p>' +
'<div class="buttons-group text-center">' +
'<a ng-click="deleteList();" class="btn">delete</a> ' +
'<a ng-click="cancelAction()" class="btn btn-cancel">cancel</a> ' +
'</div>' +
'</div>' +
'</div>' +
'</div>',
link: function (scope, element, attrs) {
scope.cancelAction = function () {
$('#delete-popup').hide();
}
var dropper;
scope.$on("DELETE_LIST", function(event, item){
dropper = item;
});
scope.deleteList = function () {
var deleteInfo =setterGetterService.getDeletePopupInfo();
var headers =deleteInfo.headers;
var params = {
"URL" :deleteInfo.restCall ,
"METHOD" : deleteInfo.method,
}
restCallService.getResponse( headers, params)
.then(function(data) {
if (data.status == "success") {
alert("groupDeleted");
$('#delete-popup').hide();
} else {
alert(data.msg);
}
});
}
}
}
});