i'm trying to edit item from a list. i'd like to show the clicked item in a modal (with all values so i can check for null id and use the modal for adding items too)
any id how i can do this?
what i currently have :
<div class="container">
<!-- The table displaing the list of item -->
<table class="table table-sm table-hover">
<tr>
<button class="btn btn-danger">
<i class="fa fa-add"></i>Remove</button>
<button class="btn btn-success" data-toggle="modal" data-target="#addOrUpdateModal">
<i class="fa fa-add"></i>Add policy</button>
</tr>
<tr>
<th class=""></th>
<th>#</th>
<th>Name</th>
<th>Options</th>
</tr>
<tr *ngFor="let policy of dataSource | paginate: { itemsPerPage: 10, currentPage: p }">
<td>
<input type="checkbox"> </td>
<td>{{policy.id}}</td>
<td>{{policy.name}}</td>
<td>
<a class="btn" (click)="showForEdit(policy)" data-toggle="modal" data-target="#addOrUpdateModal">
<i class="fa fa-pencil-square-o"></i>
</a>
<a class="btn text-danger" (click)="delete(policy.id)">
<i class="fa fa-trash-o"></i>
</a>
</td>
</tr>
</table>
</div>
<!-- Pagination directive -->
<div class="container">
<pagination-controls (pageChange)="p = $event"></pagination-controls>
</div>
<!-- the modal i'd like to use for add and update data -->
<div class="modal fade" id="addOrUpdateModal" tabindex="-1" role="dialog" aria-labelledby="addOrUpdateModal" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle"></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form role="form">
<div class="form-group">
<!-- The inputs i want to fill with clicked item -->
<input type="hidden" class="form-control" value=""/>
<input type="text" class="form-control" placeholder="Name" value=""/>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" (click)="addOrUpdate()">Do smthg</button>
</div>
</div>
</div>
</div>
i don't know how to get the data passed to the modal since the modal is not in the ngFor. should i pass the data to my controller, then make the controller display the modal somehow...?
(new to Angular5 / typescript and javascript. like.. 3 weeks exp in all of that so, sorry for dumb questions...)
although : if someone have a great book like "angular and typescript for newbies", i buy it right now! :D