generator-gulp-angular icon indicating copy to clipboard operation
generator-gulp-angular copied to clipboard

Failing to inject new modules to main app module.

Open altinselimi opened this issue 9 years ago • 3 comments

Hello there,

First, kudos for the generator, its really nice.

While setting up the environment, I tried creating a new module but when I ran gulp serve, the chrome console threw up an error :

Uncaught Error: [$injector:modulerr] Failed to instantiate module myApp due to:
Error: [$injector:modulerr] Failed to instantiate module myOwnModule due to:
Error: [$injector:nomod] Module 'myOwnModule' 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.

This is myOwnModule file:

angular
    .module('myOwnModule', [])
    .controller('SidebarCtrl', SidebarCtrl);

/* @ngInject */
function SidebarCtrl($timeout, toastr) {
    'ngInject';
    var vm = this;
    vm.text = "someRandomText";
}

and the dependency injection on index.module.js :

angular.module('myApp', ['myOwnModule', 'ngAnimate', 'ngCo...

What am I doing wrong?

altinselimi avatar Jun 10 '16 14:06 altinselimi

Upon further investigation, I came to understand the .js files were not being injected anywhere in the /tmp files. Why are they not being injected? Isn't there a gulp task to do the upmentioned?

altinselimi avatar Jun 10 '16 14:06 altinselimi

Hi altinselimi You're close - the problem seems to be with gulp/inject.js. Creating a new 'best practice'. module directory gave me the same error when the file was named mynewmodule/mynewmodule.module.js but after renaming it mynewmodule/mynewmodule.js it all worked fine with a .controller and .directive set to angular.module('mynewmodule'). ... in new .js files.

I'm pretty sure this is because the default (line 25) in gulp.inject.js is path.join(conf.paths.src, '/app/**/*.module.js') because if you change that to path.join(conf.paths.src, '/app/**/index.module.js') then mynewmodule/mynewmodule.module.js and everything else runs without errors.

Hope that helps (and yes I agree, it's a great generator and the Fuse admin theme built on top of it with ui-material is also pretty cool)

bartsmilner avatar Jun 22 '16 12:06 bartsmilner

and, of course, if you edit a gulp file you need to run gulp serve again...

bartsmilner avatar Jun 22 '16 12:06 bartsmilner