Re: [angular.js] Module-wide variables "good practice"

339 views
Skip to first unread message

Peter Bacon Darwin

unread,
Jul 20, 2012, 6:23:07 AM7/20/12
to ang...@googlegroups.com
Use a service, they are singletons and can be injected into anywhere you need them.

On 20 July 2012 11:10, Egržvýd Chálobodor <myst...@gmail.com> wrote:
I have a few vars that I want to reuse across different parts of my app, for example's sake let's say they're url strings for REST calls.
I could create a global window object to store them or mash them into the module object, although that doesn't seem to me like the Angular way.

Would creating a new .factory service, storing them inside of it and injecting the service in appropriate places be considered good practice or is there another way of doing this?
Thanks.

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/Wh8AvWedewwJ.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.

Witold Szczerba

unread,
Jul 22, 2012, 7:56:03 AM7/22/12
to ang...@googlegroups.com
I would also consider why would you like something like an URL to be
well known instead of some actual service doing it's job. I ask in the
meaning of the OOP "Tell, Don't Ask" principle.
Another thing is that maybe we would not like the system to be
directly aware of that constants, but we would like our services be
configurable. In that case you could find an answer to my question
useful:
https://groups.google.com/d/topic/angular/UioTbFjoQhI/discussion
I have not tried that yet, though.

Regards,
Witold Szczerba
Reply all
Reply to author
Forward
0 new messages