Pass ID to modal via ng-repeat Angularjs

Asked

Viewed 166 times

0

How to take the line ID (Prod.productId) on ng-repeat and switch to modal to update the record. It must be something with ng-click on the button but I’m not finding any example. Someone could give a helping hand. Thank you!

<tr ng-repeat="prod in produtos">
  <td class="text-center">{{prod.produtoId}}</td>
  <td class="text-center">{{prod.produtoOperadora}}</td>
  <td>{{prod.produtoDesc}}</td>
  <td>{{prod.produtoPreco | currency}}
    <td>{{prod.produtoPrecoConv | currency}}</td>
    <td class="text-center">
      <button id="btn" class="btn btn-info btn-sm text-white" data-toggle="modal" data-target="#updateProd">
                                    <i class="fa fa-refresh"></i>
                                </button>
    </td>
</tr>

1 answer

1

To send the id to a method in your js just put the click and call a method passing the Prod.productId as parameter.

<button id="btn" class="btn btn-info btn-sm text-white" data-toggle="modal" data-target="#updateProd" ng-click="editar(prod.produtoId)">Editar</button>

No js

editar: function(id){

}

Since the button is inside your repeat structure it will pick up the id corresponding to your table’s row.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.