So i have a service mainService
where this function that creates a promise is present:
this.myPromise = function() {
var deferred = $q.defer();
var promise = deferred.promise;
return promise;
}
And i have a controller secondController
where i want my code to run when the promise is resolved
mainService.myPromise()
.then(filterpanel)
function filterpanel(handle) { ... }
I also have a mainController
where i want to run some code and when that code succeeds i want to resolve the promise in my service
function count (a * b) {
if ((a * b) === 10) {
mainService.myPromise('ok');
}
}
I tried to change myPromise to something like this, but that doesn't seem to work. Any ideas how i can accomplish this?
this.myPromise = function(data) {
var deferred = $q.defer();
var promise = deferred.promise;
if (data) {
deferred.resolve('ok');
}
return promise;
}
EDIT: why i need this is because when my app loads, i do a connection through websocket to another application.
Communicating with that application happens in three steps
- Open a connection to the app
- Open a document
- Make an empty object
Every step returns a unique handle (ID) that handle is needed to go to the next step 1 > 2 > ...
After step 3 the unique id needs to be send to another controller.
My problem i have now is that the other controller secondController
already starts before these 3 steps are finished, so i don't have the correct handle yet.
That's why i tought of making a promise so the secondController
waits till the first controller has the correct ID.