I'm trying to manage passing a variable into a .then()
callback from a promise in ember, but the variable is removed from memory before the promise is returned.
handleResponse(params) {
this.get('model.item').then((item) => {
item.handleResponse(params);
});
}
Of course, params
is undefined when it gets passed to the item's method because it's out of scope by then.
I've worked around this by setting the params as an attribute on the controller:
this.set('params', params);
before calling the item. But there has to be a better way? I've tried binding params
to the callback: .bind(params)
but for some reason this does nothing.
Aucun commentaire:
Enregistrer un commentaire