Pass confirmFX into your controller, as in the example below:
angularApp.controller('SetorController', ['$scope', '$routeParams', '$location', '$filter', '$http', 'confirmFx',
function ($scope, $routeParams, $location, $filter, $http, confirmFx) {
$scope.deletarRegistro = function(data) {
/* aqui você coloca a requisição do banco que
faz a exclusão e dá um echo com
json_encode(['success'=>true,'message'=>'Mensagem excluída com sucesso!']);
*/
$.post('/deletar-registro', {id:data.setorId}, function(rtn) {
if (rtn.success) {
alert(rtn.message);
}
});
}
$scope.excluir = function (data) {
confirmFx('Exclusão de arquivo', 'Você confirma a exclusão?',
function () {
$scope.deletarRegistro(data);
});
};
}]);
In the view you must pass the Scope of the element you want to delete ng-click="excluir(data)"
.
In a "popup_functions.js" file the part:
function zIndexPopup() {
var zInd = parseInt($('.ui-front ').css('z-index')) + 1000;
$('.ui-front ').css('z-index', zInd)
//console.log(zInd);
}
function confirmFx(titulo, content, arrayBotoes) {
$(window).scrollTop(0);
$('body').scrollTop(0);
$("<div id='alertFx2' title='" + titulo + "' style='text-align:left'>" +
"<table style='border:none'>" +
"<tr>" +
"<td>" + content + "</td>" +
"<tr>" +
"</table>" +
"</div>").dialog({
modal: true,
buttons: arrayBotoes,
autoOpen: false,
position: {my: "top+120", at: "center top", of: window},
drag: function(event, ui) {
$(window).scrollTop(0);
$('body').scrollTop(0);
},
open: function() {
var id = $(this).attr("id");
if (id != "alertFx2") {
$(this).dialog("destroy");
}
zIndexPopup();
}
}).dialog('open');
}
Now put the modal template script in your view:
<script type="text/ng-template" id="confirmFxModal.html">
<div class="modal-header">
<h3 class="modal-title">{{title}}</h3>
</div>
<div class="modal-body" style="font-weight: normal;">
<div ng-bind-html="message">{{message}}</div>
<div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="ok()">Sim</button>
<button class="btn btn-default" ng-click="cancel()">Não</button>
</div>
</script>
Now create a standard file for angular services "servicesDefault.js":
angularApp.factory('confirmFx', ['$modal', function ($modal) {
function confirmFxCtrl($scope, title, content, $modalInstance, fnCallBack) {
$scope.title = title;
$scope.message = content;
$scope.ok = function () {
setTimeout(fnCallBack, 10);
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
}
function openPopup(title, content, fnCallBack) {
var modalInstance = $modal.open({
templateUrl: 'confirmFxModal.html',
controller: confirmFxCtrl,
size: 'sm',
resolve: {
title: function () {
return title;
},
content: function () {
return content;
},
fnCallBack: function () {
return fnCallBack;
}
}
});
return modalInstance;
}
return function (title, content, fnCallBack) {
return openPopup(title, content, fnCallBack);
};
}]);
On your view, place at the end of the body:
<script src="//code.jquery.com/jquery-latest.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script type="text/javascript" src="js/SetorController.js"></script>
<script type="text/javascript" src="js/popup_functions.js"></script>
<script type="text/javascript" src="js/servicesDefault.js"></script>
Angularjs works well with jQuery. But if you want to put a little effort into it, you can do a modal template with Angularjs. Check here: https://docs.angularjs.org/guide/templates
– Ivan Ferrer
Thanks for the tip, but I would like to see it working, I don’t understand why I can’t get {{setorId}} inside this Jquery, it’s more for 'pride' really, because it should work. But as for the Angular template, know some tutorial in Portuguese?
– Luiz Negrini
The purpose of Angularjs is to separate javascript from the view. In this case, you are making wrong use. The correct thing was to keep the whole javascript structure within the angular application. And call the method internally, passing only the controller’s Scope through the view. I’ll put an example as an answer here, ok.
– Ivan Ferrer
how do I separate the {{foo}} angular tag from the view? I think this is not wrong, but now separate into a file and have it loaded is barbada in the question jquery, only that only do it after seeing working, it is more practical to work this way.
– Luiz Negrini
Dude, this isn’t Smarty, you can’t implement variables within javascript methods. Angular does an internal treatise for html.
– Ivan Ferrer
You have to respect the working standards of Angularjs, otherwise you will not leave the place.
– Ivan Ferrer
Take the course to the free part first to understand how it works and what the proposal of Angularjs is, otherwise you will suffer face: http://campus.codeschool.com/courses/shaping-up-with-angular-js/
– Ivan Ferrer
You can’t solve the problem?
– Luiz Negrini
I can do the modal you want, but that’s not the way you’re doing it. I’ll put the answer here, for you to understand, but it will take a while.
– Ivan Ferrer
What do you call your controller? and your application name?
– Ivan Ferrer
Setorcontroller
– Luiz Negrini
@Ivanferrer awaiting your response.
– Luiz Negrini