mwaylabs / generator-m-ionic

Advanced workflows and setup for building rock-solid Ionic apps
MIT License
670 stars 133 forks source link

Fix angular module generation #334

Closed matheuscas closed 8 years ago

matheuscas commented 8 years ago

When I use the pair generator, it creates a module without dependencies, like this:

angular.module('module_name')

But this generates the following error

Error: [$injector:nomod] Module 'module_name' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

To fix this, the module should be like this:

angular.module('module_name', [])

gruppjo commented 8 years ago

Hi @matheuscas, the pair generator does not create a new module. That is done with the yo m-ionic:module subgenerator. The pair generator merely creates a controller and a template pair in a given module.

So to create a module with a controller and template pair run:

# first create module
yo m-ionic:module myModule
# create pair
yo m-ionic:pair myModule

the angular.module('module_name') line is merely a getter.

I hope I could help. If not, please feel free to reopen :)

matheuscas commented 8 years ago

So, I think you guys have to change docs, perhaps. In Quick Start you tell that I can do something like this:

yo m-ionic:<component> <name> <moduleName>

So I did it:

yo m-ionic:pair myList myModule

And it generated a template, an controller inside the new module, like it should do. But the module generation still produces an error. Whats the point of uses a generator and still have to fix it's generation? You know what I mean?

gruppjo commented 8 years ago

I think we're talking about two different things here :) I understand what you are trying to do and it's easy and there is nothing to be fixed, you just need to use it in the following fashion, that is different from how you think it works.

  1. You always have to create the module first yo m-ionic:module myModule.
  2. Then create a component. In yo m-ionic:<component> <name> <moduleName> the moduleName specifies which module the component should be created in. It does not say and intend to implicitly create that module.

The subgenerators don't create a module. You need to create the module first before you can use additional components in it. The intended use is the following and then everything works.

More detailed docs here: https://github.com/mwaylabs/generator-m-ionic/blob/master/docs/guides/sub_generators.md and refer to my last comment.

Does that answer you question?

gruppjo commented 8 years ago

Maybe it might be less confusing to make this more obvious in the quick start guide. #335 What do you think?

matheuscas commented 8 years ago

Like a said, I think you guys should improve documentation, because even the latest link, did not reached what I pointed. To Explain that part what you said to me would be clarifying to the public. Thanks for the answers and keep the great job.