【发布时间】:2018-12-14 21:07:13
【问题描述】:
我从 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>
所以无法渲染formio。任何人有想法请帮助我。
【问题讨论】:
-
没有真正的理由使用
document.createRange().createContextualFragment(template);,只需按照下面提到的LGSon。 -
嗯,发布了一个答案,但我说得对吗,它确实添加了标记,但您的
formio组件不起作用? -
如果是这样,我添加了一些可能会有所帮助的链接,其中一个甚至可能是重复的......
-
document.createRange().createContextualFragment() 和 innerHtml 都给出了相同的结果。但是问题是formio没有通过这种方式渲染,而formio直接放入html时工作正常。
标签: javascript html angular