I am working on a project using AngularJS. We are looking at using the revealing module pattern so we can have private functions in our controllers and services. Everything works as expected, except for promises/async data.
Here is an example:
export function SomeController( angularDependencies ) {
'ngInject'
const path = $stateParams.path, // this works fine
data = someService.getPromise(path) // this should return a promise
return {
path,
data // returns {} instead of a promise
}
}
My question is this: Is there a way to only do the return after I have all promises resolved? Something like this:
Promises.all(allPromises).then((res) => {
return {
path,
'data': res
}
})
I'm open to using $q, rxjs, underscore, whatever to get this to work.
UPDATE: I changed data to this:
const path = $stateParams.path,
data = Promise.resolve(someService.getPromise(path))
And now I have an object that shows up in Angular's scope, which is progress, but it's a weird object. All of the data that I want is inside of an object, _v
.
So I think I am heading in the right direction, but I'll update this if I find anything new.