AngularJS中的ng-app V/S data-ng-app [英] ng-app V/S data-ng-app in AngularJS
问题描述
在AngularJS中使用ng-app
时:在文档中找到的ng-app
将用于定义根元素以作为应用程序自动引导.
In AngularJS when using ng-app
: ng-app
found in the document will be used to define the root element to auto-bootstrap as an application.
在某些应用程序中,它被用作data-ng-app
.
In some of the application it is being used as data-ng-app
.
以下两个声明是否有任何区别,如果是,则&如果否,那么哪个重要,为什么?
Is there any difference in both of the following declaration, If Yes what & If No then which one is significant and why ?
1.
<body ng-app>
<p>{{ 1 + 2 }}</p>
</body>
2.
<body data-ng-app>
<p>{{ 1 + 2 }}</p>
</body>
推荐答案
两者都相同,不同之处在于,如果您希望模板/代码符合HTML规范并遵循最佳做法.使用data-ng-app.
Both and are the same except for the fact that if you want your template/code to be according to be HTML compliant and follow the best practices. Use data-ng-app.
这是官方文档引用:
最佳做法:建议使用破折号分隔的格式(例如ngBind的ng-bind).如果要使用HTML验证工具,则可以使用数据前缀的版本(例如data-ng-bind用于ngBind).出于遗留原因,可以接受上面显示的其他表格,但我们建议您避免使用它们."
"Best Practice: Prefer using the dash-delimited format (e.g. ng-bind for ngBind). If you want to use an HTML validating tool, you can instead use the data-prefixed version (e.g. data-ng-bind for ngBind). The other forms shown above are accepted for legacy reasons but we advise you to avoid them."
希望能回答您的问题.
Hope that answers your question.
干杯!
这篇关于AngularJS中的ng-app V/S data-ng-app的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!