NgApp without using any particular module name

Consider the code snippet below:

part of the html file:

<body ng-app> <div ng-controller="MainCtrl">{{name}}</div> </body> 

js file part:

 function MainCtrl($scope) { $scope.name = "John"; } 

I always put my controllers in some module whose name I define in an ng application. How does it work when I do not define any module?

+6
source share
1 answer

Angular has this "auto-discovery" feature that allows it to search for controllers by their name if they are defined in a global scope.

This feature is mainly intended for quick demonstrations / prototypes / fragments of the evidence-based concept, and not for real applications.


From the Angular Developer's Guide :

NOTE. Although Angular allows you to create controller functions in a global scope, this is not recommended. In a real application, you should use the .controller method of your Angular module for your application [...]


Relatively empty ngApp , if no name is specified, this means that there is no module for assigning controllers, directives, services, but apart from this, everything works fine.

+9
source

Source: https://habr.com/ru/post/970372/


All Articles