AngularJS 中的 ng-app V/S data-ng-app [英] ng-app V/S data-ng-app in AngularJS
问题描述
在 AngularJS 中使用 ng-app
时:在文档中找到的 ng-app
将用于定义根元素以作为应用程序自动引导.>
在某些应用程序中,它被用作 data-ng-app
.
以下两个声明是否有任何区别,If Yes what &如果否,那么哪个是重要的,为什么?
1.
<p>{{1+2}}</p>
2.
<p>{{1+2}}</p>
除了如果您希望您的模板/代码符合 HTML 标准并遵循最佳实践这一事实之外,两者都是相同的.使用 data-ng-app.
这是官方文档引用的内容:
"最佳实践:最好使用破折号分隔格式(例如 ng-bind 表示 ngBind).如果您想使用 HTML 验证工具,您可以改用数据前缀版本(例如 data-ng-bind 表示ngBind).上面显示的其他形式由于遗留原因而被接受,但我们建议您避免使用它们."
希望能回答您的问题.
干杯!
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.
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>
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.
This is what the official documentation quotes:
"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.
Cheers!
这篇关于AngularJS 中的 ng-app V/S data-ng-app的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!