简体   繁体   English

当 innerHTML 以 angular 完全加载时启动一个函数

[英]Start a function when innerHTML has fully loaded in angular

I was wondering if in Angular, it is possible to get informed when Inner HTML has been fully loaded.我想知道在 Angular 中,是否可以在内部 HTML 完全加载时得到通知。 I have a web application that fetches a SVG-Image from a server.我有一个从服务器获取 SVG 图像的 Web 应用程序。 I need to show it as innerHTML because I need to perform actions on the svg and also call component functions from it.我需要将它显示为innerHTML,因为我需要对svg 执行操作并从中调用组件函数。 After loading it from the server I have to do some small changes to the SVG and therefore wait untill it is completely loaded in the innerHTML.从服务器加载后,我必须对 SVG 进行一些小的更改,因此要等到它完全加载到 innerHTML 中。 At the moment I add a picture at the end of the SVG and call the function where I perform the changes on the SVG like this:目前,我在 SVG 的末尾添加了一张图片,并调用我在 SVG 上执行更改的函数,如下所示:

<img onload="smallSVGChanges(); this.parent.removeChild(this)">

But I'm pretty sure that this is not he best way to do it.但我很确定这不是他做这件事的最佳方式。

I have found a related question to this problem, but I don't think that my question is a complete duplicate of this question , because it is almost 10 years old and no angular was used there.我发现了一个与这个问题相关的问题,但我不认为我的问题是这个问题的完全重复,因为它已经有将近 10 年的历史了,而且那里没有使用 angular。

您可以简单地执行此操作<img (onload)="doSomethingOnComponent()">并在相应的打字稿文件中的组件定义内定义函数doSomethingOnComponent

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM