【发布时间】:2013-08-26 15:27:00
【问题描述】:
编辑:jsFiddle 此处为示例。
我有一个ngRepeat,它生成包含iframes 的指令。
div(ng-repeat='element in elements')
ng-switch(on="element.type")
a-directive(ng-switch-when="something")
another-directive(ng-switch-when="somethingElse")
现在,在指令中,我在某些事件之后将内容加载到 iframe 中,方法是:
$iframe[0].contentWindow.d_contents = "html"
$iframe[0].src = 'javascript:window["d_contents"]'
一切都很好。
当我从模型中(在控制器中)删除这些元素之一时:
elements.remove(object) //using sugarjs, that's not the issue, same behaviour with splice
UI 会相应更新,即元素消失。
问题
这按预期工作:
elements.push(ele1)
elements.push(ele2)
.. init iframes inside ele1 and ele2 with content ..
elements.remove(ele2)
结果:ele2 从 UI 中消失,ele1 仍然存在并加载了 iframe
这不是:
elements.push(ele1)
elements.push(ele2)
.. init iframes inside ele1 and ele2 with content ..
elements.remove(ele1)
结果:ele1 从 UI 中消失,ele2 仍然存在 iframe,但 iframe 内容恢复为空,iframe.load() 被解雇。
这里发生了什么?为什么我的 iframe 会被重置?
【问题讨论】:
-
有用信息:当您有 3 个元素并删除第二个元素时,只会重新加载第三个 iframe。
-
是的,似乎删除一个元素会将其他元素移回 1 个位置,并且指令中的某些内容发生了变化..
标签: iframe angularjs angularjs-directive ng-repeat