That would depend on whether ImageUploadProviderModule is importing AvatarChangeComponentModule or not. Leaving the current issue aside, simply based off the naming, I would consider it a red flag to have service provider modules importing component modules. I always want that relationship to be one-way. Components make use of providers. Providers make use of other providers, but never of components. So perhaps AvatarChangeComponentModule isn’t really where Camera should be living, for the overall cleanliness of the app.
ImageUploadProviderModule is only imported in avatar-change.module
Camera is imported by avatar-change.module but it’s being used inside ImageUploadProvider (which is where it’s failing) but not inside ImageUploadProviderModule
So your idea idea is move this function from ImageUploadProvider to avatar-change?
and change this line: this.uploadingAvatarImg = "data:image/jpeg;base64," + imageData;
to this: this.imageUploadProvider.uploadingAvatarImg = "data:image/jpeg;base64," + imageData;
Is that correct?
If so I’d also have to change the same thing with my SocialLoginProvider which uses Facebook and Google logins and move it to its component (login-buttons). But this one works ok
This is the way to use lazy loading. The mess comes with the other way around, having everything on app.module.
This is the best way to scale medium/big apps
If you put your ionic native providers in the app.module everything is going to be more easy, with no dependency problems. The ionic native do not belong to any module.
With large applications it is difficult to work with strong dependencies, you will have many problems. I have worked in large applications and it is my advice.
@AxelStone again that’s not a lazy loading approach. You don’t need to load something that you won’t need on you app module. With a small app it’s ok but if you have 200 components you will load all of them, which is not ideal because maybe you just want to use 5.
a component is a piece of code that you might use on a different part of your app. The logic here with lazy loading doesn’t change (at least as far as I know)
It’s only one possibility, but I like it because it gets UI stuff out of providers. I like keeping providers faceless, only dealing with network and other data-slinging. The ultimate problem is that Camera needs to be visible in the module scope of whatever class is trying to inject it.
Makes sense, but what happens if we need to call the Camera component function from another component which is not avatar-change? Would we have to repeat this function again?
If I import Camera from avatar-change it should work but as I said before I also open the camera from different components/pages so this provider is a global place to put this.
Should I create a new component just with this Camera component imported?
but what I mean is when we need a main function for the camera. For example, we use avatar-change when we have the classic “Update your avatar” option, but now, we need another function to take a picture like new-post which also uses the camera with similar camera options.
So now we have similar but different components.
Where should I place my this.camera.getPicture(options)? Should I have one function on each component?
That’s why I created here ImageUploadProvider, to have this function shared through my different camera component.
On page 1 we want to take a picture and upload it and on page 2 we want to take another picture and edit it.
We have now the same function: takePicture(). Where should we put this function if we can’t import Camera inside a provider? Should we duplicate this function?