javascript - 从 Angular 应用程序中的正文脚本将 css 样式加载到正文标记中
问题描述
我试图用这样的覆盖标签的style
属性:body
script
<script type='text/javascript'>
window.onload = function() {
document.body.style.cssText = 'color: red'
}
</script>
问题是,我将从 API Rest 生成的一些代码嵌入到 Angular 应用程序中,其中有很多限制:
- 我没有权限将代码写入 Angular 应用程序本身
- 我也无法修改
head
标签 - 这
<div id='content'>
是我可以嵌入到 Angular 应用程序中的代码
<html>
<head>...</head>
<body style=''>
<app-root>
<div id='content'>
...
<script type='text/javascript'>
window.onload = function() {
document.body.style.cssText = 'color: red'
}
</script>
...
<p>some text</p>
</div>
</app-root>
</body>
</html>
然后,当我在浏览器中加载 Angular 应用程序时,<body style=''>
它不会改变。
我尝试了一个没有 Angular 的香草样品,它按预期工作:Fiddle
由于我几乎没有 Angular 的经验,我的问题是:Angular 是否有任何约束阻止修改其范围之外的任何 html 标记?
解决方案
推荐阅读
- c# - XmlDocument.NodeInserted 在 XmlDocument.Validate() 上触发
- ios - 从后台返回后CoreData崩溃
- php - 未在 Controller 中获取 env 文件值
- search - 如何在 Visual Studio Code 中搜索特定文件名?
- docker-for-windows - 为 Windows Docker 容器分配的默认内存量?
- javascript - 使用javascript和特定条件在href url上添加参数
- ios - Rxswift 在事件发生时取消观察者并重新订阅
- android - Firebase 数据库 setValue() 和 updateChildren() 覆盖以前的值
- xaml - 通过模型的字符串值设置 IsVisible 属性
- tensorflow - 我在使用 Tensorflow 保存模型时遇到了麻烦。文件过大