简体   繁体   English

Angular 6 从 HTMLTemplateElement 创建 HTMLElement

[英]Angular 6 create HTMLElement from HTMLTemplateElement

We try to use custom elements in Angular that are created in polymer.我们尝试在 Angular 中使用在聚合物中创建的自定义元素。

Our goal is to define a HTML template that is passed to a custom element.我们的目标是定义一个传递给自定义元素的 HTML 模板。 The custom element generates the HTML based on this template.自定义元素基于此模板生成 HTML。 Angular does not pass the HTML template correctly. Angular 没有正确传递 HTML 模板。 It seems that angular renders HTML templates in a different way.似乎 angular 以不同的方式呈现 HTML 模板。

A simple example in plain Javascript:纯 Javascript 中的一个简单示例:

https://stackblitz.com/edit/js-svh54x?file=index.js https://stackblitz.com/edit/js-svh54x?file=index.js

innerHTML untouched未触及的内部 HTML

A simple example in Anuglar 6: Anuglar 6 中的一个简单示例:

https://stackblitz.com/edit/angular-zryvwi?file=src%2Fapp%2Fapp.component.ts https://stackblitz.com/edit/angular-zryvwi?file=src%2Fapp%2Fapp.component.ts

Removed innerHTML删除了innerHTML

Why does angular remove the innerHTML of the HTMLTemplateElement?为什么angular 会删除HTMLTemplateElement 的innerHTML?

Using使用

<template id="testTemplate" [innerHTML]="'<div>Test 123!!!</div>'"></template>

instead of代替

<template id="testTemplate">
    <div>Test 123!!!</div>
</template>

Solved my problem.解决了我的问题。

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

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