5

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>

2
  • 2
    This is a good question. The docs say that the name is optional, but fail to explain how to create the module when no name is given. Commented Sep 17, 2014 at 15:03
  • stackoverflow.com/questions/12988506/… Commented Aug 27, 2015 at 4:39

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes I want added directives
0

Just change myApp to the name of the module you wish to use.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.