data ng model-ng-app和ng-app的区别

相关文章推荐
angular指令心得(ng-model)在项目中编写指令,常常会依赖其他的指令来实现想要达到的功能,其中最常用到的便是ng-model,它为我们明确了需要绑定的属性,虽然在指令中可以通过通过使用独立...
angular中ng-bind和ng-model的区别
1、问题背景
ng-model:把元素或变量绑定到应用程序2、实现实例
AngularJS之ng-model命令
单个angular页面能否有两个ng-app?
ng-app是声明angular的作用边界的。
divng-app="app1"ng-init="func1()">div>
(1) 监督式学习(supervised learning) 和 非监督式学习(unsupervised learning)
监督学习:监督学习,简单来说就是给定一定的训练样本(这里一定要注意,...
吴恩达机器学习课程的学习笔记~
Andrew Ng机器学习笔记week1第一周主要是对机器学习进行简单的介绍和线性回归的知识点:一、Introductionmachine learning的举例
machine learnin...
机器学习笔记week1(Andrew NG)martin机器学习笔记week1Andrew NG
Linear Regression with one Variable单变量线性回归
Model an...
Coursera上的Andrew Ng《机器学习》学习笔记Week1
作者:雨水/家辉,日期:,CSDN博客:http://blog.csdn.net/gobitan
注:本课...
https://www.coursera.org/learn/machine-learning/lecture/rkTp3/cost-function
Cost Function
他的最新文章
他的热门文章
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)ng-app V/S data-ng-app in AngularJS - Stack Overflow
Join Stack Overflow to learn, share knowledge, and build your career.
or sign in with
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 ?
&body ng-app&
&p&{{ 1 + 2 }}&/p&
&body data-ng-app&
&p&{{ 1 + 2 }}&/p&
11.1k62744
3,02611734
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
"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.
See the answer:
Only diffrence regarding html5 validation
ng-app isn't strictly valid html.
Custom attributes should be prefixed with data- to be valid.
So angular added this syntax so users could still have valid html.
(Knockout also uses data- attributes.)
There is absolutely no difference in functionality.
ng-app and data-ng-app both are similar to each other, the only difference between them is sometimes HTML validators will show an error while using ng-app. so that time you can use data-ng-app.
note: x-ng-app also have the same property.
You can use x-ng-app too instead of using data-ng-app.
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabled3被浏览134分享邀请回答暂时还没有回答,开始写第一个回答2 个回答被折叠()问题对人有帮助,内容完整,我也想知道答案
问题没有实际价值,缺少关键内容,没有改进余地
例如ng-app="app",如果angular.module("app",[]);中的名字不定义为"app"的话会报错。
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
ng-app 是整个angular应用的入口,他会根据ng-app指定的名称去寻找对应的angular模块,如果不一致就无法找到对应的模块进行初始化。所以应用的根模块名称必须和ng-app指定的名称一致
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
ng-app 是整个应用程序的入口,所以必须和入口的module名一致,一个应用程序只能有唯一一个ng-app
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
一个angular应用中,可以有多个angular.module。应该有且只有一个angular.module的名称与ng-app的值一致,否则就没有意义了。
angular.module('M1',[]);
angular.module('M2',[]);
angular.module('Mn',[]);
angular.module('app',['M1','M2',...,'Mn']);
M1,M2,...,Mn可能是不同的业务模块,可以单独作为一个angular.module,最后全部挂载在app模块下。
-----------------------------------分割线---------------------------------------------------
以上是自动加载。如果采用手动加载,则不受名称限制,不受app数量限制。
&!DOCTYPE html&
&meta http-equiv="Content-Type" content="text/ charset=utf-8" /&
&script src="/libs/angular.js/1.4.6/angular.min.js"&&/script&
&div id="app1"&
&div ng-controller="myCtrl"&
{{ hello }}
&div id="app2"&
&div ng-controller="myCtrl"&
{{ hello }}
&script type="text/javascript"&
var app1 = angular.module("test1",[]);
app1.controller("myCtrl",function($scope){
$scope.hello = "a Angular app";
var app2 = angular.module("test2",[]);
app2.controller("myCtrl",function($scope){
$scope.hello = " another Angular app";
angular.bootstrap(document.getElementById("app1"),['test1']);
angular.bootstrap(document.getElementById("app2"),['test2']);
以上例子,启动了两个angular app,且没有使用ng-app指令。
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
谢谢各位的耐心解答
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
一定要一样的 因为这是最首要的angular绑定
同步到新浪微博
分享到微博?
关闭理由:
删除理由:
忽略理由:
推广(招聘、广告、SEO 等)方面的内容
与已有问题重复(请编辑该提问指向已有相同问题)
答非所问,不符合答题要求
宜作评论而非答案
带有人身攻击、辱骂、仇恨等违反条款的内容
无法获得确切结果的问题
非开发直接相关的问题
非技术提问的讨论型问题
其他原因(请补充说明)
我要该,理由是:
在 SegmentFault,解决技术问题
每个月,我们帮助 1000 万的开发者解决各种各样的技术问题。并助力他们在技术能力、职业生涯、影响力上获得提升。
一线的工程师、著名开源项目的作者们,都在这里:
获取验证码
已有账号?3被浏览5411分享邀请回答&div ng-app&
&input ng-model="name" type="text" placeholder="请输入姓名"&
&p&我的姓名: {{name}}&/p&
&div ng-app&
&input ng-model="age" type="number" placeholder="请输入年龄"&
&p&我的年龄: {{age}}&/p&
效果都是这样的:如果需要加载多个ng-app,需要手动加载,完整代码类似如下:&!DOCTYPE html&
&html lang="en"&
&meta charset="UTF-8"&
&title&sample&/title&
&script src="angular.js"&&/script&
&div id="A1" ng-app="app1"&
&input ng-model="name" type="text" placeholder="请输入姓名"&
&p&我的姓名: {{name}}&/p&
&div id="A2" ng-app="app2"&
&input ng-model="age" type="number" placeholder="请输入年龄"&
&p&我的年龄: {{age}}&/p&
&script type="text/javascript"&
var app1 = angular.module("app1",[]);
var app2 = angular.module("app2",[]);
angular.bootstrap(document.getElementById("A2"),['app2']);
它的执行效果:31 条评论分享收藏感谢收起0添加评论分享收藏感谢收起写回答

我要回帖

更多关于 angular data ng app 的文章

 

随机推荐