为什么 ngif 不从我的代码中删除脚本标签? [英] Why does ngif not remove script tags from my code?

查看:31
本文介绍了为什么 ngif 不从我的代码中删除脚本标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个脚本标签要根据条件删除.在 DOM 中,我看到它们不存在(它们已被注释掉),但我仍然看到控制台从它们中喷涌而出.不管脚本标签是否加载?如果是这样,有没有人对此有任何解决方法?

I have a few script tags I want removed on a condition. In the DOM I see that they are not there (they're commented out), but i still see console spew from them. Are the script tags loaded regardless? If so, does anyone have any workaround for this?

<script ng-if="myCondition" src="blah blah.js"></script>

推荐答案

它们是否被移除并不重要.到 angular 引导程序并开始 DOM 操作时,浏览器将编译所有脚本标签.

It wouldn't matter if they were removed or not. By the time angular bootstraps and starts DOM manipulation all script tags will have been compiled by browser.

删除脚本标记不会删除已经编译的代码.

Removing a script tag does not remove the code that has already been compiled.

没有更多关于您要完成什么或脚本做什么的信息,目前只能提供这些信息.

Without a lot more information on what it is you are trying to accomplish , or what the scripts do, this is about all that can be offered for now.

我建议您阅读有关在将 html 编译为 DOM 时浏览器如何处理网页的基础知识.一旦它遇到带有 src 的脚本标签,就会对该文件发出请求,并且无法拦截它.

I would suggest you read up on the basics of how a web page gets processed by the browser as the html gets compiled to the DOM. The instant it encounters a script tag with an src , a request is made for that file and there is no way to intercept it.

这篇关于为什么 ngif 不从我的代码中删除脚本标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆