Simplify an Angular Service using a JavaScript Object as a Value Provider

Share this video with your friends

Send Tweet

Often it might be simply easier to create the implementation out of a simple JavaScript object rather than a full blown class. That’s where value providers come in play!

Viktor Soroka
~ 6 years ago

Thanks for sharing. Should any of really helper utils functions be placed in the providers rather than just importing them via 'import' statement?

Juri Strumpflohnerinstructor
~ 6 years ago

🤔 well that really depends what kind of helper you're having. It's totally fine to also just import them. Usually if I just have single functions, I do exactly that. However if those functions then again depend on other functions etc, I tend to create services and make use of the dependency injection mechanism. Basically when the dependency chain gets bigger. Also because that helps during testing since you can then provide mocks more easily.