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

查看:65
本文介绍了为什么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>

推荐答案

是否删除它们并不重要.到有角度的引导程序启动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天全站免登陆