You can observe the change in the scope property in your directive.
For example, add confirm-show-when
<button confirm="delete(id)" ... confirm-show-when="state.showConfirmDialog" ... > Delete </button>
Add it to your directive definition
.directive('confirm', ['$modal', function($modal) { return { restrict: 'A', scope: { confirm: '&', title: '@confirmTitle', message: '@confirmMessage', confirmButtonText: '@confirmButtonText', cancelButtonText: '@cancelButtonText', showWhen: '=confirmShowWhen' }, link: function(scope, element, attributes) { var showModal = function() { var modal= $modal.open({ controller: 'ConfirmModalController', templateUrl: 'template/modal/confirm.html', size: 'sm', scope: scope }); modal.result.then(function() { scope.confirm(); }, function() {
And in your controller, just set showConfirmDialog to true when you want to show it.
// controller code // set up the state object so we use the 'dot' notation $scope.state = { showConfirmDialog: false }; // other controller code if (userWantsToDelete) { $scope.state.showConfirmDialog = true; }
JoseM source share