Angular reload existing promise

I have a service that returns a promise to a controller:

// .... in the service
this.RefreshData = function() {
    this.data = $q.all( {images: ...., tags: ....}); 
}
RefreshData ();

// .... in the controller
function() OnImages() {.....};
ImageSrv.data.then(OnImages());

      

But now something has happened somewhere else and I want to update my controller. Let's say some directive calls my service. and updates it

ImageSrv.RefreshData();

      

My promise has changed, now OnImages doesn't fire. Is the correct way to handle this promise + event? I'm sorry that I can't just do something like

ImageSrv.data.refresh() 

      

which will change the promise to "not resolve" and try to resolve it again.

+3


source to share


1 answer


This is not how promises work. There is no mechanism for making promises know that they have changed. promises resolve (or reject) once and then execute. There is nothing to tell the controller that something has changed and OnImages

needs to be started again.



One solution might be to fire some event that your controller will listen to and then re-fire OnImages

.

0


source







All Articles