angular-fullstack / generator-angular-fullstack

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

Factories and Components not compatible? #2279

Open MarinAngelo opened 7 years ago

MarinAngelo commented 7 years ago
Item Version
generator-angular-fullstack 3.7.5
Node 6.5.0
npm 3.10.3
Operating System Ubuntu 16.04
etc etc
Item Answer
Transpiler Babel / TypeScript
Markup HTML / Pug
CSS CSS / LESS / SCSS / Stylus
Router ngRoute / ui-router
Client Tests Jasmine / Mocha
DB MongoDB / SQL
Auth Y / N
etc etc

Hi there

I have some problems with adding factories and components to my project. Are the new items that are genereted by yo compatible to older verseions? To me it seams not to be so and I do not understand the code at all, things like (export and require). How can a add items that fit into the syntax of version 3.7.5?

Kind Regards

Marinus

Awk34 commented 7 years ago

3.x.x versions of the generator use 0.x.x versions of generator-ng-component, as you can see here.

4.x.x versions of the generator bundle front-end code using Webpack. There is nothing stopping you from using factories and Angular 1.5 components in either major version.

MarinAngelo commented 7 years ago

Hi, thanks for your reply! Does this mean that in my app version 3.7.5 I can use "yo angular-fullstack:service myService" as usual and it should work? In the console I get: ReferenceError: require is not defined

Awk34 commented 7 years ago

If you're trying to run yo angular-fullstack commands for a project, your generator-angular-fullstack major version that's installed globally needs to match the generator-angular-fullstack major version that you scaffolded with. So if you scaffolded with 3.7.5, you should have generator-angular-fullstack@^3.7.5 installed globally.

MarinAngelo commented 7 years ago

OK, then I have the wrong verstion ( 3.8.5) how can I change the version? I have uninstalled the current generator and then installed again with command "npm install -g generator-angular-fullstack@3.7.5" but it still installed version 3.8.5.

Awk34 commented 7 years ago

The latest version of 3.x.x is 3.8.0, so I think you're looking at the wrong version. Try npm list -g --depth=0

MarinAngelo commented 7 years ago

ok, I have the following entry: /home/marinus/.nvm/versions/node/v6.5.0/lib ├── bower@1.7.9 ├── generator-angular-fullstack@3.7.5 ├── gulp-cli@1.2.2 ├── npm@3.10.3 └── yo@1.8.5 But when I run a sub generator I get still uncompatible code. Do I have tu use the subgenerators also with "@3.7.5" at the end (yo angular-fullstack:route@3.7.5 myroute )?

Awk34 commented 7 years ago

Do me a favor and check npm list -g generator-angular-fullstack --depth=1. This will show which version of generator-ng-component you have installed. Also, what is under generatorVersion in your .yo-rc.json file?

MarinAngelo commented 7 years ago

/home/marinus/.nvm/versions/node/v6.5.0/lib └── generator-angular-fullstack@3.7.5

.yo-rc.json:

"generator-angular-fullstack": { "generatorVersion": "3.7.5",

Awk34 commented 7 years ago

npm list -g generator-angular-fullstack --depth=1 should print out all the top-level dependencies of your installed generator-angular-fullstack. Are you sure you put it in correctly?

MarinAngelo commented 7 years ago

yes, I'm sure, just made it again and have same output.

Awk34 commented 7 years ago

Strange. Maybe try a rm -rf /home/marinus/.nvm/versions/node/v6.5.0/lib/generator-angular-fullstack and then re-install?

MarinAngelo commented 7 years ago

Hi, I have utilized your recipe, it does not change anything, I've got still the same output after running "npm list -g generator-angular-fullstack --depth=1". And when adding a new route I still get the wrong code. E.g. *.component.js*** 'use strict'; const angular = require('angular');

const uiRouter = require('angular-ui-router');

import routes from './portrait.routes';

export class PortraitComponent { /@ngInject/ constructor() { this.message = 'Hello'; } }

export default angular.module('svsAppApp.portrait', [uiRouter]) .config(routes) .component('portrait', { templateUrl: 'app/portrait/portrait.html', controller: PortraitComponent, controllerAs: 'portraitCtrl' }) .name;


instead of: ***.controller.js****** 'use strict'; (function(){

class MreleaseComponent { constructor() { this.message = 'Hello'; } }

angular.module('svsAppApp') .component('mrelease', { templateUrl: 'app/mrelease/mrelease.html', controller: MreleaseComponent });

})();