iframe - What happens when removing an object used by a ngRepeat in AngularJS? -


edit: jsfiddle example here.

i have ngrepeat spawns directives containing iframes.

div(ng-repeat='element in elements')     ng-switch(on="element.type")          a-directive(ng-switch-when="something")         another-directive(ng-switch-when="somethingelse") 

now, inside directive loading content iframe after event, doing:

$iframe[0].contentwindow.d_contents = "html" $iframe[0].src = 'javascript:window["d_contents"]' 

everything works nicely.

when remove 1 of these elements model (in controller) like:

elements.remove(object) //using sugarjs, that's not issue, same behaviour splice 

the ui gets updated accordingly, i.e. element disappear.

the problem

this works expected:

elements.push(ele1) elements.push(ele2)  .. init iframes inside ele1 , ele2 content ..  elements.remove(ele2)  

result: ele2 disappears ui, ele1 still there iframe loaded

this not:

elements.push(ele1) elements.push(ele2)  .. init iframes inside ele1 , ele2 content ..  elements.remove(ele1)  

result: ele1 disappears ui, ele2 still there iframe, iframe content empty, , iframe.load() gets fired.

what happening here? why iframe getting reseted?

you need add loading logic inside load() reload content when dom changes.

var linkfn = function (scope, element, attrs) {     init(function () {         var $iframe = element.find("iframe")          var refresh = function () {             var doc = $iframe[0].contentwindow.document;             doc.open();             doc.write(scope.ele.source);             doc.close();         }          $iframe.load(function () {             console.log(scope.ele.id + ": loaded ");              //refreshing             refresh();         });          //initial loading         refresh()     }) } 

you need use doc.write() scenario or recursive loop error.

demo


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -