Call function javascript in route


#1

Hi all, I’m a newbie with emberjs, I want to show a notify after create, update, delete with sweetAlert plugin. so how to call sweetAlert function in route?

Thanks.


#2

I’m also new to Ember, but what’s wrong with calling it from inside your actions directly? In your create/update/delete actions, just put it in the callback or the then/catch block of your action.

something along the way of this:

export default Ember.Component.extend({
  actions: {
    delete(id) {
      this.get('ajax').post('/things/delete', {
        data: {
          id
        }
      }).then((response) => {
        sweetAlert('Done!');
      }).catch((error) => {
        sweetAlert('Oops! ' + error);
      });
    }
  }
});