首页 > 解决方案 > 从 Angular 应用程序中的正文脚本将 css 样式加载到正文标记中

问题描述

我试图用这样的覆盖标签的style属性:bodyscript

<script type='text/javascript'>
    window.onload = function() { 
        document.body.style.cssText = 'color: red' 
    }
</script>

问题是,我将从 API Rest 生成的一些代码嵌入到 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 标记?

标签: javascripthtmlcssangular

解决方案


推荐阅读