It sounds like you want to inject the service into all components, which isn't possible to do automatically and, I would argue, would be very bad.
You have to reference the injectable in your component's constructor. The other solution, as Sander said, is to create your service in the global namespace (ex. "window.myGlobalService = ...") and you can then reference it everywhere. On Fri, Jul 8, 2016 at 1:03 PM, Paulo Coutinho <[email protected]> wrote: > Ok, > > But the question is about receiving this "injection". > > The only way to inject my global service is from the constructor? Or i can > create a component with any constructor and on "OnInit" i set > "this.myService = ???". > > Thanks. > > > On Fri, Jul 8, 2016 at 2:00 PM, 'Lucas Lacroix' via AngularJS < > [email protected]> wrote: > >> My understanding is that all injected dependencies are singletons. >> So, if you inject the same type of thing in multiple places, you should >> receive the single instance of that thing. >> >> On Fri, Jul 8, 2016 at 12:58 PM, Paulo Coutinho <[email protected]> >> wrote: >> >>> Hi, >>> >>> I need a global service with variables that dont change across the >>> application. >>> >>> You can see my project as an example: >>> >>> https://github.com/prsolucoes/gohc >>> >>> >>> I have on header the count/list of running jobs. I need that every >>> second this new informations change on this global service and this >>> information will be used to show the list of running jobs too. >>> >>> >>> Thanks. >>> >>> >>> >>> >>> Em 8 de jul de 2016 4:24 AM, "Sander Elias" <[email protected]> >>> escreveu: >>> >>>> Hi Paulo. >>>> >>>> May I ask for your use-case? do you wan't/need some kind of global? >>>> I'm not aware of a way to do it through the injector. However, it is >>>> possible to create a real singleton service(that you can use in and outside >>>> angular), that you put into the global space. >>>> >>>> regards >>>> Sander >>>> >>>> -- >>>> You received this message because you are subscribed to a topic in the >>>> Google Groups "AngularJS" group. >>>> To unsubscribe from this topic, visit >>>> https://groups.google.com/d/topic/angular/shzB6YcCHZ8/unsubscribe. >>>> To unsubscribe from this group and all its topics, send an email to >>>> [email protected]. >>>> To post to this group, send email to [email protected]. >>>> Visit this group at https://groups.google.com/group/angular. >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "AngularJS" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> To post to this group, send email to [email protected]. >>> Visit this group at https://groups.google.com/group/angular. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> >> >> -- >> Lucas Lacroix >> Computer Scientist >> System Technology Division, MEDITECH <http://ehr.meditech.com> >> 781-774-2293 >> >> -- >> You received this message because you are subscribed to a topic in the >> Google Groups "AngularJS" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/angular/shzB6YcCHZ8/unsubscribe. >> To unsubscribe from this group and all its topics, send an email to >> [email protected]. >> To post to this group, send email to [email protected]. >> Visit this group at https://groups.google.com/group/angular. >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > Atenciosamente, > Paulo Coutinho. > *PR**S** - Soluções Inteligentes* > > Site: www.prsolucoes.com > Blog: www.pcoutinho.com > Skype: paulo.prsolucoes > Telefone: +55 21 99386-0010 > > -- > You received this message because you are subscribed to the Google Groups > "AngularJS" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/angular. > For more options, visit https://groups.google.com/d/optout. > -- Lucas Lacroix Computer Scientist System Technology Division, MEDITECH <http://ehr.meditech.com> 781-774-2293 -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
