When
<html ng-app="myApp">
Then i get module:
angular.module('myApp', []);
var mod = angular.module('myApp')
mod.controller('MyController',
function ($scope) {})
I am interested in how to choose the default module when <html ng-app>
From viewing the AngularJS source code. I can only guess that the default name for a ng-app
module is either just app
or ngApp
or ng-app
. You'll have to try those three to see which one works.
The ng-app
directive is used to create a module via the HTML. If there is no np-app
directives defined in the HTML, then you have to assign a module to the DOM using angular.bootstrap
. Without a module an AgularJS application will not work.
When you exclude the module name from ng-app
a default module is created. This module allows you to use AngularJS directives in the HTML.
The tutorial has a few examples of just <html ng-app>
being used. That's because there is a lot you can do with AngularJS without writing any JS code. If you're just going to use built-in directives, then you don't have to define a name.
If you want to make changes to the module (such as adding custom directives) then you should assign it a name.
The default name for a module is not a documented standard, and it could change in the future.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With