angular-fullstack / generator-angular-fullstack

Yeoman generator for an Angular app with an Express server
https://awk34.gitbook.io/generator-angular-fullstack
6.12k stars 1.24k forks source link

possible issue with angular-fullstack:route #2164

Closed jhancock1975 closed 8 years ago

jhancock1975 commented 8 years ago
Item Version
generator-angular-fullstack 4.0.1
Node 3.6.1
npm 3.10.3
Operating System Linux Mint 17.1 Rebecca

I am using generator-angular-fullstack version 4.0.1 % npm list -g --depth=0 | grep generator-angular-fullstack ├── generator-angular-fullstack@4.0.1

after running

angular-fullstack:route games

angular-fullstack generates files properly under client/app/games, but browsing to http://localhost:3000/games only re-directs to the home page.

I have to add two things to client/app/app.js:

import games from './games/games.component';
...
angular.module('meanTutorialApp', [
    // ngAnimate,
    ngCookies, ngResource, ngSanitize, uiRouter, uiBootstrap,
    // ngMessages,
    navbar, footer, main, constants, util, games  ])
  .config(routeConfig);

N.B: I had to add, "games," to the list of modules.

After that, when open the application in a browser (http://localhost:3000), I get a totally blank screen.

Looking at the browser (chrome) JavaScript console, I see

angular.js:68Uncaught Error: [$injector:modulerr] Failed to instantiate module meanTutorialApp due to:
Error: [$injector:modulerr] Failed to instantiate module meanTutorialApp.games due to:
Error: [$injector:strictdi] function($stateProvider) is not using explicit annotation and cannot be invoked in strict mode...

Copying off of the main module, I see I am missing this line

 'ngInject';

directly under the line

export default function($stateProvider) {

In client/app/games/routes.js After adding that, the site loads again, and I can browse to http://locahost:3000/games

Awk34 commented 8 years ago

Thanks for the report. I definitely know that the generator won't import the new module and add it to your main DI list, but I'm not sure how to go about doing something about that. If we automatically inject an import of every new module into the main app file, it sets people up for a not-so-optimized app (especially for lazy-loading). A lot of the time, you don't want your new module to be imported by the main app file. On the other hand, it might confuse people that they can't immediately use the route. I'm thinking the best thing to do might just be to add instructions after an Angular subgenerator is run about importing the new module and adding it to another module's DI list.

The 'ngInject'; part needs to be fixed for sure, though.

Awk34 commented 8 years ago

generator-ng-component 1.0.2 has been published to fix the 'ngInject' issue

krokhale commented 8 years ago

How about if you automatically inject an import of every new module into the main app file, but then comment it out by default. The user then has the option to uncomment it out.

Awk34 commented 8 years ago

@krokhale I don't think that's a very good idea. That has both the effects of not importing the new module immediately, so the route is automatically reflected, and always adding the data to the main app.js, which can lead to bad practices.

mikodigital commented 8 years ago

thanks for solution

Awk34 commented 8 years ago

https://github.com/DaftMonk/generator-ng-component/commit/174e46c167d32c101a0aad7907db229356205523