在NG-应用指令的位置(HTML VS体) [英] Placement of the ng-app directive (html vs body)

查看:92
本文介绍了在NG-应用指令的位置(HTML VS体)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近回顾了code与角度建立了一个Web应用程序,发现它是用 NG-应用=MyModule的指令放在写的&LT;身体GT; 标记。在学习的角度,我只看过它用在&LT; HTML&GT; 标签,所推荐的角文档的here 这里,并在他们的<一个HREF =htt​​p://docs.angularjs.org/tutorial/step_00>教程。

I recently reviewed the code for a webapp built with angular and found that it was written with the ng-app="myModule" directive placed on the <body> tag. When learning angular, I've only ever seen it used on the <html> tag, as recommended by the angular docs here, here, and in their tutorial.

我这个探索我自己了一下,发现SO问题,值得注意的的这个同样这个,即讨论加载多个模块的网页。但是,这种技术从我的情况不同,因为它涉及配售NG-应用上的元素中的 的身体,使用手动引导在同一时间运行两个角的应用程序。

I've explored this a bit on my own and found SO questions, notably this one and similarly this one, that discuss loading multiple modules for a page. However, this technique different from my case, as it involves placing ng-app on elements within the body and using manual bootstrapping to run two angular apps at the same time.

据我所知,有一个在应用程序之间运行时使用 NG-应用&LT没有差别; HTML&GT; &LT;身体GT; 。据我了解, NG-应用指定角应用程序的根,所以它的&LT安置;身体GT; 将削减&LT; HEAD&GT; 出棱角分明的范围,但我想不出任何主要方式,这将影响到的东西。所以我的问题是:什么是对这些标签,而不是其他的东西之间​​放置 NG-应用的技术差异

As far as I can tell, there is no difference at runtime between an app with ng-app on <html> or <body>. As I understand it, ng-app designates the root of an angular application, so placement of it on the <body> would cut <head> out of angular's scope, but I can't think of any major way this would affect things. So my question is: What are the technical difference between placing ng-app on one of these tags instead of the other?

推荐答案

有就是你把 NG-应用

如果你把它放在&LT;车身方式&gt; 那么你有AngularJS一个较小的范围,即更快

If you put it on <body> then you have a smaller scope for AngularJS which is slightly faster.

不过,我已经使用 NG-应用&LT; HTML&GT; 用于操纵&LT;标题方式&gt;

But I have used ng-app on the <html> for manipulating the <title>.

这篇关于在NG-应用指令的位置(HTML VS体)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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