However I can’t load data from providers on components. What am I missing here? I imported provider to components.module.ts and components.module.ts is properly imported on app.module.ts. I don’t see any set up that is particularly preventing components from accessing providers.
import { DataProvider } from '../../providers/data/data';
import 'rxjs/add/operator/debounceTime';
Other pages can access data object array in DataProvider without any problem… but component01 still can’t access dataprovider… I wonder what’s missing.
Don’t register your provider with two different modules. You have two choices: either (1) register the provider with app.component.ts, or (2) register the provider with each smaller module you want to use it in.
If you do (1), you create a single, global instance of a provider that can be injected anywhere. if you do (2), you create a unique instance of the provider that can only be injected within the scope of the module. So with (2), you can create multiple copies of the same provider. Most of the time, you’ll want the information in the provider available anywhere, so making a single copy of the provider is better.
if you do (2), create a ModuleWithProviders instead of an NgModule, to register your providers and components.
I had a strange example today - I tried to redesign one of my pages to use ion-grid but the custom component did not work (reported a data bug) - put back into a simple div and it worked fine.
Thanks for your help so far. I’m working on Ionic conference app. You can start a conference app demo and create component and then try to load any data array to the component using *ngFor. It could be that there’s something wrong with this conference app, not ionic / angular 5… I’m really confused because everything seems alright but it’s not working.
@JAR19 yes, other pages can load from data array easily. Nothing seems to be wrong with data array… I tried to add import to data provider … but no luck. Thanks
@jamesharvey - sometimes the simply things are overlooked - when I am working on components I have to restart ionic serve to see any changes made to the components (apart from the css which works immediately).