These are chat archives for AngularClass/NG6-starter

20th
Jan 2016
Andrew Lombardi
@kinabalu
Jan 20 2016 03:31

Here’s how I’m doing it:

import myService from ‘./myService';
import routing from './services.config';

export default angular
  .module('app.services', [])
  .service({
      bandService
  })
  .config(routing)
;

all within a services.js

and the myService.js

export default class MyService {

    constructor(Restangular) {
        "ngInject";
        this.Restangular = Restangular;
    }
}
Andy Brown
@brownish
Jan 20 2016 03:36
import myService from ‘./myService';
import routing from './services.config';

export default angular
  .module('app.services', [])
  .service('myService', myService)
  .config(routing)
;
@kinabalu ^^ does that work?
Andrew Lombardi
@kinabalu
Jan 20 2016 04:44
@brownish i’ll try that
Andy Brown
@brownish
Jan 20 2016 05:02
@kinabalu then when you inject that service into your controllers make sure you use whatever you have in quotes, not the name of the service class itself
Andrew Lombardi
@kinabalu
Jan 20 2016 07:23
@brownish ok. and to be sure, it does work fine in the constructor, gets injected there, just in calls from the UI that it is resulting in undefined
Andy Brown
@brownish
Jan 20 2016 07:52
@kinabalu so it works fine in the controller's constructor?
Andrew Lombardi
@kinabalu
Jan 20 2016 14:37
@brownish yes
Andy Brown
@brownish
Jan 20 2016 19:45
hmm
@kinabalu is your controller part of a component/directive?
you can log other controller variables from the html?
Sergey Protko
@fesor
Jan 20 2016 21:45
@kinabalu bandService is undefined in your example
Andy Brown
@brownish
Jan 20 2016 21:45
yep
Sergey Protko
@fesor
Jan 20 2016 21:46
you imported myService but using bandService variable
Andy Brown
@brownish
Jan 20 2016 21:46
  .service({
      bandService
  })
needs to be:
.service('myService', myService)
im suprised there wasn't some big angular error when trying to load the first page
Sergey Protko
@fesor
Jan 20 2016 21:46
Just lost what the discussion was about :)
Andy Brown
@brownish
Jan 20 2016 21:46
lol
Sergey Protko
@fesor
Jan 20 2016 21:47

im suprised there wasn't some big angular error when trying to load the first page

you could register anything you want as a service, even undefined variable

but this is really strange…
Andy Brown
@brownish
Jan 20 2016 21:47
but when trying to inject that service it should have complained about no provider for it
i would think
Sergey Protko
@fesor
Jan 20 2016 21:49
you registered service, so there is provider
Andy Brown
@brownish
Jan 20 2016 21:50
.service({ bandService }) for this?
Sergey Protko
@fesor
Jan 20 2016 21:50
yep
Andy Brown
@brownish
Jan 20 2016 21:50
how would you inject that without the string name for it?
Sergey Protko
@fesor
Jan 20 2016 21:50
this is ES6 thing
Andy Brown
@brownish
Jan 20 2016 21:50
hmm
Andy Brown
@brownish
Jan 20 2016 21:51
ah i see, so then he would be able to inject bandService?
so that would basically be the same as .service({bandService: bandService})
Sergey Protko
@fesor
Jan 20 2016 21:52
yep
this notation allows you to register multiple services with a single .service call
Andy Brown
@brownish
Jan 20 2016 21:52
oh interesting
Sergey Protko
@fesor
Jan 20 2016 21:52
but this not working for .component :(
Andy Brown
@brownish
Jan 20 2016 21:53
bummer
Sergey Protko
@fesor
Jan 20 2016 21:53
I think I’ll prepare PR for this in next few days
Andrew Lombardi
@kinabalu
Jan 20 2016 23:57
ok this makes me want to test this now
so I’ve done it right? but it hates me...