简体   繁体   English

Angular 9:在 ngFor 循环中使用模态

[英]Angular 9: Using Modal in ngFor loop

I have a list of varieties generated by a for loop.我有一个由 for 循环生成的品种列表。 Each item in that list has a button beside it so that particular list item can be updated.该列表中的每个项目旁边都有一个按钮,以便可以更新特定的列表项目。 Each button will open up a modal where you can enter new informations.每个按钮都会打开一个模式,您可以在其中输入新信息。 I don't want an unlimited amount of modals on the page, so I put the modal inside the for loop and want to pass the a iterator to the modal but always it displays the value 0 which is the first value of a.我不希望页面上有无限数量的模态,所以我将模态放在 for 循环中,并希望将 a 迭代器传递给模态,但它始终显示值 0,这是 a 的第一个值。

<tr *ngFor="let a of list; ; let i=index" >
    <td> {{ i }} </td>
    <td> <button data-toggle="modal" data-target="#editproject">Update</button> </td>
    <div class="modal fade" id="editproject">
       <input type="text" id="edit-contact-name" class="form-control" placeholder="{{ a }}" >
    </div>
</tr>

I am not sure you can use {{}} inside input element.我不确定您是否可以在输入元素中使用 {{}}。 You can create a modal component.您可以创建一个模态组件。 and pass the value of 'a' to the component as an attribute.并将“a”的值作为属性传递给组件。 <modal-component [a]="a"></modal-component>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM