【发布时间】:2017-03-24 14:29:36
【问题描述】:
我正在显示大约 5 个面板,其中从一个数组呈现,然后显示每个面板都有自己的 ID、名称和要共享的内容。在每个面板中,我都有一个展开图标,我允许用户将选定的面板展开成一个大模式。我正在使用引导程序中的示例,但当前当我单击以模式打开时 - 它以大模式打开,但它为数组中的每个项目打开,而不仅仅是选定的面板。这是我到目前为止所拥有的:
<div class="col-sm-4" *ngFor="let item of items; let i = index">
<div class="panel panel-warning">
<div class="panel-heading">
{{item.title}}
<div class="box-header-btns pull-right">
<a title="Expand" type="button" data-toggle="modal" data-target=".bs-example-modal-lg">
<i class="glyphicon glyphicon-resize-full"></i>
</a>
</div>
</div>
<div class="panel-body modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
{{item.content}}
</div>
</div>
</div>
</div>
</div>
我的数组循环显示面板:
items: Array<Panel> = [
new Panel(1, 'panel 1', 'show text', 'test data in modal'),
new Panel(2, 'panel 2','show image', 'more test data'),
new Panel(3, 'panel 3', 'show graph', 'more and more data')
];
class Panel {
constructor(
public id: number,
public title: string,
public footer: string,
public content: any)
}
目前,当我为一个项目打开一个模式时,它还会在模式关闭之前循环遍历所有其他项目。
【问题讨论】:
-
你的 expandPanel() 方法是什么样的?
-
请减少缩进,难以阅读
-
也请发布您的模态 HTML 部分,另外根据我的说法,您需要动态提供
data-target -
实际上,我认为这里的问题是您正在为
ngFor的 每个 迭代创建一个独特的模式对话框 -
@aluanHaddad 我想了想并添加了更多代码,希望它会有所帮助。我可以看到 ngFor 是如何导致模态循环的,但不确定如何分离但仍能正常工作。
标签: jquery twitter-bootstrap angular