0
votes

I'm trying to call my controller's action from my view with Ember, but it says:

Uncaught TypeError: Cannot call method 'send' of null

I just can't find the right way to work with views in ember.

My view layout has a call like:

<button type="button" {{action modalConfirmation target="view"}} class="btn btn-primary">Save changes</button>

And my View class tries to call the controller in this fashion:

this.get('controller').modalConfirmation();

My Controller has something like this:

ProjEmber.BananasIndexController = Ember.ArrayController.extend({
  actions: {
    showModal: function() {
        modalinaView.title = "My Title";
        modalinaView.templateName = "any_template_you_wish";
        modalinaView.append();   
    },
    modalConfirmation: function() {
      console.debug('Action modalConfirmation');
    }
  }
});

OBS: it works if I append my view using the helper like this:

{{#view ProjEmber.ModalinaView title='A title'}}
    A not so good application of a modal view. Just for the sake of illustration.
{{/view}}

You can see the full source on Github, especifically this part of the commit: https://github.com/lucaspottersky/ember-lab/commit/4862426b39adc0bbcce0b4cc3fd0099439f8dd55#commitcomment-4421854

2
When you append is it creating it correctly beside the actions? - Kingpin2k

2 Answers

0
votes

There is a good likelihood it's failing to be appended within the body, or the scope of your ember app which would be why the events aren't propagating to your actions hash.

You might try appendTo('body')

0
votes

You shouldn't access view like this

var modalinaView = this.container.lookup('view:modalina');

This PR can give you more insights.

You are doing the same as Stefanpenner has done in this commit.

And this is Wycats reply.

Alternatively, This answer may help you in instantiating modals