2

I'm pretty clear on how angular.module works, but this eludes me for whatever reason.

In my code I have the following

var app = angular.module("myApp", [])

app.controller("MainCtrl", ...)

but my code only works when there is no array for dependent modules, like this:

     var app = angular.module("myApp"); 
     app.controller("MainCtrl",...)

I haven't the slightest the clue as to what would cause the problem, as I've always understood the need for the empty array.

1 Answer 1

2

I've always understood the need for the empty array

Array as the second argument is only needed when the module is created. So with

angular.module("myApp", [])

you create new module. And with

angular.module("myApp") 

you retrieve already existent module which was previously created.

my code only works when there is no array for dependent modules

It means that you have already created module myApp. In this case you don't have to recreate it again, as it will erase all previously registered controllers, etc.

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

1 Comment

that's weird. I'm using this controller to create the module to begin with...I guess not. I guess I'll have to figure out where it was already created. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.