mardi 14 mars 2017

Ember: insert errors from model in application template

I saw the becameError and becameInvalid triggers within the Model Class, for example:

//model/car.js
example  import Ember from "ember";
import Model from "ember-data/model";

export default Model.extend({
  becameError() {
    alert('there was an error!');
  },

  becameInvalid(errors) {
    alert(`Record was invalid because: ${errors}`);
  },
});

Now when I save the model and my backend returns an error, the alert will be shown. But how can I display the error message within the application template?

Something like:

becameError() {
    applcation.set('hasError', true);
  },

//application.hbs

   <h1>An error has occured!</h1>





Aucun commentaire:

Enregistrer un commentaire