admin管理员组文章数量:1321070
Consider the piece of code below:
part of html file:
<body ng-app>
<div ng-controller="MainCtrl">{{name}}</div>
</body>
part of js file:
function MainCtrl($scope) {
$scope.name = "John";
}
I always put my controllers in some module, whose name I define in ng-app. How it works when I don't define any module ?
Consider the piece of code below:
part of html file:
<body ng-app>
<div ng-controller="MainCtrl">{{name}}</div>
</body>
part of js file:
function MainCtrl($scope) {
$scope.name = "John";
}
I always put my controllers in some module, whose name I define in ng-app. How it works when I don't define any module ?
Share Improve this question asked Jun 5, 2014 at 7:49 Adrian BaranAdrian Baran 8958 silver badges24 bronze badges1 Answer
Reset to default 9Angular, has this "auto-discover" feature, that allows it to look up controllers by their name if they are defined on the global scope.
This feature is mainly intended for quick demos/prototypes/proof-of-concept snippets and not real-world applications.
From Angular's Developer Guide:
NOTE: Although Angular allows you to create Controller functions in the global scope, this is not remended. In a real application you should use the
.controller
method of your Angular Module for your application [...]
Regarding the empty ngApp
, if there is no name specified, it only means that there is no module to assign controllers, directives, services to, but other than that everything works fine.
本文标签: javascriptngApp without using any specific module nameStack Overflow
版权声明:本文标题:javascript - ngApp without using any specific module name - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742080580a2419674.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论