This is angularjs. For some reason, I need to create the popup inside the controller. So I have something like this:
var popupTemplate =
'<div class="modal fade">' +
' <div class="modal-dialog">' +
' <div class="modal-content">' +
' <div class="modal-header">' +
' <button type="button" class="close" data-dismiss="modal">×</button>' +
' </div>' +
' <div class="modal-body">' +
' <div>You sure?</div>' +
' </div>' +
' <div class="modal-footer">' +
' <button type="button" class="btn btn-primary" data-dismiss="modal">OK</button>' +
' <button type="button" class="btn btn-link" data-dismiss="modal">Cancel</button>' +
' </div>' +
' </div>' +
' </div>' +
'</div>';
To open the modal I run this:
var themodal = $(popupTemplate).modal();
I need to know if the user clicked on the OK-button. Unfortunately adding an "ng-click" causes problems. Nothing is executed. I have read a little about compiling and/or using data-ng-click. But none of those worked.
So I was thinking about listening to the promise. But having:
themodal.then(function(){
console.log("test");
})
Results in the error "themodal.then is not a function".
I then tried running this instead:
var dialog = $modal.open(popupTemplate);
dialog.result.then(function(){
//Do stuff with respect to closure
});
But I then get a "$modal-open is not a fucntion".
Even though I included '$modal' in my app.
Which of them should I use and how can I make one of these approaches work?