Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular.module name by default

Tags:

angularjs

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>

like image 999
Michael Phelps Avatar asked Nov 01 '22 17:11

Michael Phelps


1 Answers

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.

like image 152
Reactgular Avatar answered Nov 11 '22 02:11

Reactgular