아마 알고 계시 겠지만 - Polymer는 여러 가지 이유로 인해 이스케이프 처리되지 않은 HTML 바인딩을 금지합니다. Polymer - innerHTML - 부모 요소의 스타일을 적용 할 수 있습니까?
How to display html inside template?
How to inject HTML into a template with polymer
그러나 내 프로젝트에 외부 소스에서 HTML을 적용 할 요구했다.구성 요소는 < 에코 - HTML >라는 그러므로 내가 구현 한 :
<dom-module id="echo-html">
<template>
<style>
</style>
</template>
</dom-module>
<script>
(function() {
Polymer({
is: 'echo-html',
properties: {
html: {
type: Object,
value: '',
observer: '_refreshHtml'
},
},
_refreshHtml: function() {
if (this.html) {
var value = '';
var container = Polymer.dom(this).parentNode;
if ((this.html.constructor == Array) && (this.html.length == 1)) {
value = this.html[0];
} else {
value = this.html;
}
if (this.parentNode) {
this.outerHTML = value;
}
this.scopeSubtree(container, true);
$(this).removeClass('echo-html');
}
},
});
})();
</script>
내가 가진 문제는이 구성 요소가 정확히 순수 HTML을 결합 그래서 내가 < 페이지를 사용할 때 > 또는 < 강한 > 또는 다른 요소를 사용하면 단순히 부모의 구성 요소 스타일을 사용할 수 없으므로 전역 스타일을 사용해야합니다.
예를 들어, 그래서 부모 요소의 스타일을 적용 할 수있는 방법이 있나요 :
<parent-element>
<echo-html html$="{{some-nasty-html}}"></echo-html>
</parent-element>
는 "일부-불쾌한-HTML"그것에 .parent-element
클래스를 포함?
.echo-html
클래스도 제거 할 수 있습니까?
Polymer.dom(this).innerHTML = '<p>My Paragraph!</p>';
그림자 DOM 그것으로 : 사실이 내 질문 :
는 당신에게 innerHTML을 모두 상속 요소에 스타일을 적용합니다 확실 : 당신이 문제의 어떤 의견이 있으면 여기
저장소에 대한 링크입니까? –DOM API를 랩핑하면 appendChild가 내 요소에서 작동합니다. 다른 요소를로드하면 importHref 및 createElement로 전달하는 적절한 방법이 있습니다. – adaliszk