Reputation: 889
I am trying to add modal in my project so that if i click on the one link the modal should show name of that particular link.
But it giving me an Error
please check below link
Upvotes: 2
Views: 27532
Reputation: 372
in this example, i show how to pass Id to bootstrap modal because not a good idea to identify the model by another field than Id
<button class="btn btn-primary"
data-toggle="modal"
[attr.data-target]="'#Model'+category.idCategory">Open Model
</button>
<div class="modal fade in"
id="Model{{category.idCategory}}"
tabindex="-1"
role="dialog"
aria-labelledby="exampleModalLabel"
aria-hidden="true">......
</div>
Upvotes: 0
Reputation: 889
Got answer from this link
Update The code in
we should use
<button type="button" class="btn btn-primary" data-toggle="modal"
[attr.data-target]="'#'+products.name">
{{products.name}}
</button>
Upvotes: 2
Reputation: 18399
It is better to use angular version of bootstrap to do this, that plays nice with angular change detection.
e.g. https://ng-bootstrap.github.io/#/components/modal/examples
Then you will have one component representing your modal, and to pass data to it, just declare public property and do this:
const modalRef = this.modalService.open(YourModalComponent);
(modalRef.componentInstance as YourModalComponent).yourProperty = yourValue;
Btw to fix the error you are talking about, you could use attr
property binding, like this:
<button type="button" class="btn btn-primary" data-toggle="modal" [attr.data-target]="'#' + products.name">
It will fix the error, but the modal is still not working, looks like you are also missing CSS there.
Upvotes: 10