1

I have on action handle in my custom view. I need to call this method from my mixin.

Js:-

App.TestView = Ember.View.extend({
    actions: {
        myClick: function () {
           // doing something here
        } 
    }
});

App.ActionMixin = Ember.Mixin.create({
    actions: {
        callMyClick: function () {
           // how do I call view's 'myClick' method here?
        } 
    }
}); 

That Test View is a custom view which is derived by {{view "test"}}. This view will share that parent controller.

I need to access that 'myClick' method from my another common mixins (Action Mixin) inside of 'callMyClick' method.

Kindly help me out of this handle.

Priyanga V
  • 241
  • 2
  • 9
  • possible duplicate of [Calling a controllers method in another controller Ember](http://stackoverflow.com/questions/22861316/calling-a-controllers-method-in-another-controller-ember) – GJK Mar 16 '15 at 16:18
  • @GJK Thanks for your reply. But my real need is to do between custom view and mixins only. – Priyanga V Mar 17 '15 at 12:33
  • If you're adding the mixin to your custom view, it should be the same solution: `this.send('myClick')`. – GJK Mar 17 '15 at 14:06
  • @GJK Again thanks for your reply and patience. I tried that what you said. I am getting an error message while doing that action as **" Nothing handled the action 'myClick'. If you did handle the action, this error can be caused by returning true from an action handler in a controller, causing the action to bubble."** This is why I came here. – Priyanga V Mar 18 '15 at 04:36
  • Are you actually adding the mixin to the view? It should look something like: `Ember.View.Extend(App.ActionMixin, { ... })` – GJK Mar 18 '15 at 12:23
  • It seems to work OK for me. [Here's a JSBin](http://emberjs.jsbin.com/gujiwucofa/1/edit?html,js,output) showing it in action. – GJK Mar 18 '15 at 12:36
  • @GJK Thanks for your reply with workaround. I gave my code example in jsbin link here, http://emberjs.jsbin.com/rutivu/3/ – Priyanga V Mar 18 '15 at 15:46
  • Your mixin is added to your route, not to your view. Your problem is that you want to send an action from a route to a view, which isn't possible. Views are kind of walled gardens: actions can go out, but not come in. If you find yourself needing to send an action to a view from a route, you might need to restructure your code a bit. – GJK Mar 18 '15 at 16:43
  • @GJK Thanks for your clear clarification. I'll try to modify at my end. – Priyanga V Mar 19 '15 at 04:24

0 Answers0