[英]Function not calling added with document.getElementById('someId').appendChild()
I am getting fraction part of HTML code from api, want to render into DOM like below... 我正在从api获取HTML代码的一部分,想渲染成如下所示的DOM ...
// getting template from backend. let template1 = "<div class='well'><formio src='example/text.json'></formio>"; //appearing into dom, but not loading form. // second way let template2 = "<formio [src]='getUrl()'></formio></div>"; // calling getUrl from component.ts file. // attaching template into DOM using appendChild() method.. const fragment = document.createRange().createContextualFragment(template); document.getElementById('landingTemplate').appendChild(fragment); getUrl() { return 'example/text.json'; } // getUrl() not calling from HTML.
<div id="landingTemplate"></div>
so unable to render formio. 因此无法渲染formio。 Anyone have idea please help me. 任何人都有主意请帮助我。
When you have HTML markup in a string, use innerHTML
当字符串中包含HTML标记时,请使用innerHTML
document.getElementById('landingTemplate').innerHTML = template;
Updated 更新
If it does add the markup but your formio
component doesn't work? 如果确实添加了标记,但您的formio
组件不起作用? ... then here are couple links that might be what you are looking for: ...然后这是您可能正在寻找的几个链接:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.