We can achieve the same without using angular-ui. This can be done using angular directives.
First add the directive to the modal.
<div class="modal fade" my-modal ....>...</div>
Create a new angular directive:
app.directive('myModal', function() {
return {
restrict: 'A',
link: function(scope, element, attr) {
scope.dismiss = function() {
element.modal('hide');
};
}
}
});
Now call the dismiss() method from your controller.
app.controller('MyCtrl', function($scope, $http) {
// You can call dismiss() here
$scope.dismiss();
});
I am still in my early days with angular js. I know that we should not manipulate the DOM inside the controllers. So I have the DOM manipulation in the directive. I am not sure if this is equally bad. If I have a better alternative, I shall post it here.
The important thing to note is that we cannot simply use ng-hide or ng-show in the view to hide or show the modal. That simply hides the modal and not the modal backdrop. We have to call the modal() instance method to completely remove the modal.