In this video tutorial, I walk through a simple of example of when it would make sense to create a provider in Ionic and how to do it. Blog post: www.joshmorony.com/how-why-an... Learn Ionic: www.joshmorony.com/building-m...
Excellent work! Showing the first way without a provider and then refactoring to use a provider made it very clear why a provider is a good idea. I also expect using a provider will make testing easier as well. Based on this I have purchased your ebook package. Thank you.
It depends on the context but in general, I prefer accessing through the provider directly, it can make the code a lot simpler. For example, if I assigned the result of the load method to a variable in the page, and then later update add or delete some item, I need to make sure I update the local reference in the page as well (perhaps directly or I could have an observable set up). If the template is accessing the provider directly then you don't need to worry about any of that, as soon as the provider updates the template will.
I was about to ask the same question, Nice answer Josh. I see your point. All this time I was following what khocef is doing. Thanks a lot for the nice tutorials, they are really helpful :) cheers
Uncaught (in promise): Error: No provider for Http! Error at Error (native) at g (localhost:8100/build/polyfills.js:3:7133) at injectionError (localhost:8100/build/main.js:1511:86) at noProviderError (localhost:8100/build/main.js:1549:12) at ReflectiveInjector_._throwOrNull (localhost:8100/build/main.js:3051:19) at ReflectiveInjector_._getByKeyDefault (localhost:8100/build/main.js:3090:25) at ReflectiveInjector_._getByKey (localhost:8100/build/main.js:3022:25) at ReflectiveInjector_.get (localhost:8100/build/main.js:2891:21) at NgModuleInjector.get (localhost:8100/build/main.js:3856:52) at resolveDep (localhost:8100/build/main.js:11260:45) at createClass (localhost:8100/build/main.js:11117:35) at _createProviderInstance (localhost:8100/build/main.js:11086:17) at createProviderInstance (localhost:8100/build/main.js:10927:64) at createViewNodes (localhost:8100/build/main.js:12293:49) at createRootView (localhost:8100/build/main.js:12208:5)