How to pass asynchronous data onto the modal controller, like ui-bootstrap modal resolve ??
opened this issue · comments
Although according to the docs and examples, you can pass data onto the modal controller using the third parameter data
in dialogs.create('address/to/modal/template.html', 'ModalController', data, opts)
, this is only good for ready data only, and not for asynchronous data.
UI-Bootstrap native modal, has the resolve
property to handle asynchronous data, and since this library is build on top of that, how would I got on utilizing this functionality of UI-Bootstrap Modal?
I already tried passing a resolve
property inside the fourth parameter opts
var opts = {'resolve': {'asyncData': fnWhichReturnsPromise()}};
dialogs.create('address/to/modal/template.html', 'ModalController', data, opts);
but although the function did get called upon opening the modal, I dont know how to get the retrieved data onto my ModalController
. I already tried injecting the key name of my async data but with no luck
/* @ngInject */
function ModalController ($modalInstance, data, asyncData) {} // this produce an error stating unknown provider asyncData
Resolve only resolves 'data'
so the default controllers behave in a consistent and predictable manner.
See https://github.com/m-e-conroy/angular-dialog-service/blob/master/src/dialogs-services.js#L260
You can fire the modal when the data is available ...
var asyncData = fnWhichReturnsPromise().then(function (result) {
data.asyncData = result;
return dialogs.create('/address/to/modal/template.html', 'ModalController', data).result;
}, function () {
// something bad happened
})