每个
ChildComponent
元素使用相同的
id="delete_category"
.Bootstrap模式使用与id匹配的第一个,并且总是第一个
子组件
具有
demoInput == 1
更改两行可以修复它
<div class="modal fade" id="delete_category{{demoInput}}" role="dialog">
<button type="button" class="btn btn-danger" data-toggle="modal"
attr.data-target="#delete_category{{demoInput}}">
还要注意添加的
attr.
用于属性绑定。
使现代化
您可以使用随机值
demoInput
在里面
id="delete_category{{demoInput}}"
.
似乎没有必要使用与中相同的值
everySecond(value)
。仅在
id
和
attr.data-target
需要在一个内保持相同
子组件
同时,它们需要在不同的
ChileComponent
s
我会用
class ChildComponent {
private static cmpId = 0;
// getter to make it available for binding from the template
// because this doesn't work with statics
private get componentId() => ChildComponent.prototype.cmpId++;
// I'm not sure if this ^^^ is the correct way to access static
// fields in TypeScript.
}
<div class="modal fade" id="delete_category{{componentId}}" role="dialog">
<button type="button" class="btn btn-danger" data-toggle="modal"
attr.data-target="#delete_category{{componentId}}">