Chris B.
Chris B.

Reputation: 90259

How do I call a function from an Angular Bootstrap modal (using angular-strap)?

I'm using Angular JS (with Angular Strap), and I'm trying to get a save confirmation dialog working.

I have a clear function which looks like this:

$scope.clear = function(confirm) {
  if ($scope.dirty && !confirm) {
    $modal({template: '/save.html', show: true, backdrop: 'static'});
    return;
  } 

  // clear the data
}

I then have the following buttons in my modal dialog:

<button type="button" class="btn" ng-click="clear(true);hide()">Discard Changes</button>
<button class="btn btn-primary" ng-click="hide()">Cancel</button>

This displays the dialog just fine, and hides it as well, no matter which button I click. But it never calls the clear function. What's going on?

Upvotes: 3

Views: 3821

Answers (1)

Mr.MAD
Mr.MAD

Reputation: 121

You need to send the scope($scope) in the $modal

$modal({ 
 template: '/save.html', 
 show: true, 
 backdrop: 'static',
 scope: $scope
});

Now you can use $parent.clear() or just clear() as the scope has been sent to the modal.

Upvotes: 1

Related Questions