HEAD 与 BODY 中的 AngularJS [英] AngularJS in HEAD vs BODY

查看:25
本文介绍了HEAD 与 BODY 中的 AngularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在所有 AngularJS 示例中,Angular 库都放在文档的 HEAD 标签中.我有一个基于 HTML5 样板布局构建的现有项目.这定义了 JS 库应该放在 DOM 的最底部 </BODY> 标签之前.

In all of the AngularJS examples, the Angular library is placed in the HEAD tags of the document. I have an existing project that has been built upon the HTML5 Boilerplate layout. This defines that JS libraries should be placed at the very bottom of the DOM before the </BODY> tag.

AngularJS 需要放在 HEAD 中吗?

Does AngularJS need to be placed in the HEAD?

推荐答案

AngularJS 不需要放在 HEAD 中,实际上你通常不应该,因为这会阻止加载 HTML.

AngularJS does not need to be placed in the HEAD, and actually you normally shouldn't, since this would block loading the HTML.

但是,当您在页面底部加载 AngularJS 时,您将需要使用 ng-cloakng-bind 以避免flash of未编译的内容".请注意,您只需要在index.html"页面上使用 ng-cloak/ng-bind.当使用 ng-include 或 ng-view 或其他 Angular 构造在初始页面加载后拉入附加内容时,该内容将在显示之前由 Angular 编译.

However, when you load AngularJS at the bottom of the page, you will need to use ng-cloak or ng-bind to avoid the "flash of uncompiled content". Note that you only need to use ng-cloak/ng-bind on your "index.html" page. When ng-include or ng-view or other Angular constructs are used to pull in additional content after the initial page load, that content will be compiled by Angular before it is displayed.

另见https://stackoverflow.com/a/14076004/215945

这篇关于HEAD 与 BODY 中的 AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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