Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emberjs abort transition and show modal

I want to abort transition on a particular route and show a modal. This is how my route code looks like:

export default Ember.Route.extend({
  model: {/* some code here */},
  actions: {
    willTransition: function(transition) {
      if (!this.controller.get('model.name')) {
        console.log('aborting transition');
        transition.abort();
        this.send('showModal', {
          template: 'campaign/campaign-name-modal',
          controller: this.controller,
          model: this.controller.get('model')
        });
      }
      else {
        // Bubble the `willTransition` action so that
        // parent routes can decide whether or not to abort.
        return true;
      }
    }
  }
});

and then in my application.hbs, I have:

{{outlet 'modal'}}

What I am observing is that transition aborts but my modal doesn't show up. When I switch the ordering to something like:

    this.send('showModal', {
      template: 'campaign/campaign-name-modal',
      controller: this.controller,
      model: this.controller.get('model')
    });
    console.log('aborting transition');
    transition.abort();

the transition doesn't abort at all.

I am not exactly sure why this might be happening. Any pointers?

like image 689
Rajat Avatar asked Jul 16 '15 18:07

Rajat


1 Answers

Maybe try editing your conditional to use firstObject:

if (!this.controller.get('model.firstObject.name')) {
like image 182
Gary Wilson Avatar answered Nov 10 '22 13:11

Gary Wilson