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

New client Service/Factory #2218

Closed Abdizriel closed 8 years ago

Abdizriel commented 8 years ago
Item Version
generator-angular-fullstack 4.0.1
Node 6.5.0
npm 3.10.3
Operating System OS X 10
Item Answer
Transpiler Babel
Markup HTML
CSS SCSS
Router ui-router
Client Tests Mocha
DB SQL
Auth Y

I am trying to add service/factory for my component and initialize it in $onInit. However I am getting this error:

angular.js:13920 Error: [ng:areq] Argument 'fn' is not a function, got undefined

You can find what I am doing there: https://gist.github.com/Abdizriel/c170e7579c8d27562743c429d4b2a80c

I have tried few different methods like instead of class export function with services object inside like I was doing in pre 4.0 version or try both methods with export default and results was similar or information that there is no provider for ActivityService.

I would be very glad if somebody could help me solve this issue.

Awk34 commented 8 years ago

You need to export an Angular 1.5 module instead of just the class. We provide a subgenerator to do this for you: yo angular-fullstack:service myservice.

Ex:

class Foo {}

export default angular.module('myApp.myService', [])
  .factory('FooService', Foo)
  .name;