Peter Boomsma
Peter Boomsma

Reputation: 9808

Naming Angular modules

I'm trying to clean up my Angular app a little bit and when I came to my app.js.coffee file I ran into some things I have little knowledge of because I copy/pasted it from another source and it seemed to work.

To my knowledge every controller, service, filter etc. needs a ,

angular.module('nameOfModule')

But 2 (or more) controllers can't have the same module name because then Angular outputs an error,

Error: [ng:areq] Argument 'nameOfModule' is not a function, got undefined

But it seems the module name that you give a controller such as nameOfModule can be used on multiple services,

addMovieService.js

angular.module('addMovieseat')

  .factory('movieAdd',

movieSearchService.js

angular.module('addMovieseat')

  .factory('MovieSearch',

So I'm starting to wonder what the module names are for.

Upvotes: 1

Views: 522

Answers (2)

Jay Patel
Jay Patel

Reputation: 5793

Add dependency for your angular module and if not then put it blank like this

angular.module('nameOfModule',[])

Error is occured because you don't add dependency for your module.

Upvotes: 1

Tarun Dugar
Tarun Dugar

Reputation: 8971

But 2 (or more) controllers can't have the same module name

This assumption is incorrect! Modules almost always have more than one controllers. In fact it is the highest level in an angular app and the module, along with all other entities (controllers, services, factories) comprise of a self sustaining AngularJS app.

For using another app inside another app, you just include the module as a dependancy like this:

angular.module('secondApp', ['firstApp'])

Upvotes: 0

Related Questions