I want to display information about the rejected model promise in my Ember error templates. The Ember error routing documentation says:
The "reason" for the error (i.e. the exception thrown or the promise reject value) will be passed to that error state as its model.
So here is some code trying to test this, with an application route that rejects a promise with an error message, and an error route and template that tries to display it:
App.Router.map(function() {
this.route('fail');
});
App.FailRoute = Ember.Route.extend({
model: function() {
return new Ember.RSVP.Promise(function(resolve, reject) {
reject('This is an error message');
});
}
});
App.ErrorRoute = Ember.Route.extend({
setupController: function(controller, model) {
this._super.apply(this, arguments);
// This always alerts with "Error model is null", when I expect
// "Error model is This is an error message" instead
alert('Error model is ' + model);
}
})
And the error template:
<h2>An error happened</h2>
{{#if model}}
Message: {{model}}
{{else}}
But no message was given
{{/if}}
When I try to do this, my error route (and therefore template) never receives the rejection object as its model.
Here is a JSBin with the above code.
Aucun commentaire:
Enregistrer un commentaire