[英]Angular - How to call ngOnDestroy when change [src] in iFrame
I have one slide show application that support only many internal link.我有一个仅支持许多内部链接的幻灯片放映应用程序。
HTML HTML
<iframe width="100%" id="iframeSlide" height="100%" #iframe frameBorder="0" [src]="urlSafe"></iframe>
TS code TS代码
current.urlSafe = current.sanitizer.bypassSecurityTrustResourceUrl(current.slideUrls[current.index]);
slideUrls
is an array contains list of internal link, but when new url set to current.urlSafe
, the old url did not call ngOnDestroy
function to release resource. slideUrls
是一个包含内部链接列表的数组,但是当新 url 设置为current.urlSafe
,旧 url 没有调用ngOnDestroy
函数来释放资源。
I tried to set current.urlSafe = "about:blank";
我试图设置
current.urlSafe = "about:blank";
or或者
var frame = document.getElementById("iframeSlide"),
frameDoc = frame.contentDocument || frame.contentWindow.document;
frameDoc.removeChild(frameDoc.documentElement);
But it did not call ngOnDestroy
function.但它没有调用
ngOnDestroy
函数。 In the internal page, I used setInterval function so need go to ngOnDestroy
to clear the Interval
, without it many request to called inside setInterval
.在内部页面中,我使用了 setInterval 函数,所以需要去
ngOnDestroy
清除Interval
,没有很多请求在setInterval
内部setInterval
。
Links I refereed我推荐的链接
https://web.dev/detached-window-memory-leaks/ https://web.dev/detached-window-memory-leaks/
Changing the iframe src would be the equivalent to navigating to a new url in the browser address bar.更改 iframe src 相当于导航到浏览器地址栏中的新 url。 The browser itself clears the top level JS/HTML resources in this case
在这种情况下,浏览器本身会清除顶级 JS/HTML 资源
ngOnDestroy
would occur if you remove components or services within the app, but not on a refresh如果您删除应用程序中的组件或服务,但不会在刷新时发生
ngOnDestroy
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.