css - 如何在 Angular 中的父组件的 iframe 内容中应用字体
问题描述
我在演示组件中有 iframe。
<iframe
id='contentIframe'
class="iframeContent"
[src]='templateUrl'
(load)="onLoadIframe()"
sandbox="allow-same-origin allow-scripts"
frameborder="0"
height="600px"
style="width:100%;"
>
</iframe>
在我的父组件(演示组件)中,我能够应用自定义字体“Open sans”。我无法将相同的字体应用于父组件内的 iframe 中的内容。
我尝试了下面的代码,但没有工作。
if (this.currentTemplate != null && this.currentTemplate != undefined) {
const bodyElement = Array.from(templateHtml.getElementsByTagName('body'));
const selectElements = Array.from(templateHtml.getElementsByTagName('select'));
for (const element of bodyElement) {
if(element.classList.contains("contentBody")) {
element.style.fontFamily = "Open Sans";
}
}
}
解决方案
推荐阅读
- javascript - 使用数组中的任何递归项构造 JSON Schema
- r - 在 R 中绘制值和 Lat Lon
- typescript - 打字稿:使用变量作为键时检查记录属性是否未定义
- data-structures - 如何使此代码用于检测链接列表中的回文涵盖所有情况?
- angular - Angular 单元测试 - 带有模拟服务的组件
- javascript - ReactJS,如何在元素渲染后显示随机值并将其返回状态?
- tableau-api - Tableau-根据组、学生类型、学位类型创建层次结构
- python - Pandas - 如何将重复的项目组合成一个具有多列的项目
- javascript - 如何从 Chrome 扩展的 textarea 中获取文本?
- ios - 使用多核解析 JSON