SharpCoder
SharpCoder

Reputation: 19163

Passing value to bootstrap modal popup in angular app

I have created some tags with the help of span & ng-repeat. when user clicks on remove button on any of the tag, I open a modal pop-up. This modal-pop has a delete button. This delete button in turn calls one function.

I want to pass some information to this delete function but I am not sure how to pass id of remove button to modal-pop up that comes up.

Here is the fiddle for same.

<div ng-app>
    <div ng-controller="TodoCtrl">
        <div ng-app="" ng-init="names=['One','Two','Three']">
            <ul>
                <li ng-repeat="x in names"> <span class="tag label label-info">
  <span>{{x}}</span>
 <a data-toggle="modal" data-target="#confirm-delete"><i class="remove glyphicon glyphicon-remove-sign glyphicon-white"></i></a> 
                    </span>
                </li>
            </ul>
        </div>
        <div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                         <h4 class="modal-title" id="myModalLabel">Confirm Delete</h4>

                    </div>
                    <div class="modal-body">
                        <p>You are about to delete one track, this procedure is irreversible.</p>
                        <p>Do you want to proceed?</p>
                        <p class="debug-url"></p>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button> <a ng-click="deleteMe()" class="btn btn-danger btn-ok" data-dismiss="modal">Delete</a>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

Upvotes: 3

Views: 1882

Answers (1)

Manish Kr. Shukla
Manish Kr. Shukla

Reputation: 4477

Adding a ng-click will solve your problem. But the approach will be a little be tweaked here.

Add a ng-click to the a tag.

  <a data-toggle="modal" ng-click="setID(x)" data-target="#confirm-delete">
      <i class="remove glyphicon glyphicon-remove-sign glyphicon-white">
      </i>
   </a> 

And then add a temp variable to hold the value to be removed (in your case x)

  $scope.setID = function(x) {
      $scope.valueToBeRemoved = x;
  };

And you can now access that variable in the delete method.

Updated plunker here

Upvotes: 3

Related Questions