Backward navigation in ionic

People I have a problem. I have 3 views: configuration, confwizard and photoprofile.

Confwizard calls directly to photoprofile in order to take a photo and save it in the storage. When photoprofile has finished calls navctrl.back(). Once threat has returned to configuration, event ionViewDidEnter() has triggered and then I got the picture from storage and cleaned it.

But, in the case of configuration I have 3 components each one in a different segment. One component calls to photoprofile for getting a photo. But when it returns to the view, neither, ionViewDidEnter(), onInit(), onChanges() has triggered on the return.

My problem is that I use the same view photoprofile for both views. I need one event to be triggered when it returns to the component.

One solution I think is to pass the view name to photoprofile and use navigatback instead back and modify the parameter in order to force the method onChanges to be triggered.

Please, could any one help me with this issue.

While you wait for somebody who shares your affinity for lifecycle events, I’m going to take a stab at convincing you to solve this without them.

You don’t control when lifecycle events fire, nor should you. You can rely on some things, like the fact that if there are paired ones, like OnInit and OnDestroy, you won’t get the same one called twice in a row without an intervening call to the other. So they are great for wiring things up and tearing them down.

They have (naturally) absolutely nothing to do with the lifecycle of business layer objects, which you do control. Instead of trying to force those two disparate things into a relationship, embrace the separation. Have your own PhotoService that all the components that care about photos inject. PhotoService can expose an Observable<Photo>. Components that display the current photo can subscribe to that when they are created, and unsubscribe when they are destroyed. Components that change the notion of the current photo can call another method in PhotoService to do this. All of that happens completely orthogonally to the lifecycle of the components themselves, which depends on a bunch of factors, many of which are totally out of your control.

All that being said, I probably won’t convince you, and that’s OK. If you do decide to persist on your current course, I’ll leave you with one more word of warning:

Do not do anything that relies on the string representation of class or property names. It will work flawlessly until you try to build the app in production mode, and then it will break hard, because part of the production build process involves running minimizers that change the string names of classes and properties.

I loved your answer because your point of view. I didn’t think about an observable or a service. The only issue I have with that solution is that I am newbie and I don’t know how to make a service that have a view in order to take the photo, let crop it and finally return it.
Could you make me some example?

Ordinarily you want to refrain from direct DOM access in an Ionic app, but this is a case where I think it’s OK to bend the rules a bit, because you shouldn’t need to actually insert the element into the document. You can use document.createElement("canvas") to spawn an HTML <canvas> element, at which point you can use the API documented here to do the transformation work on your image, such as cropping, resizing, or rotating.