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.
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.
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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…