Ember 2 action sent to route instead of component

Cereal Killer

In my app I've defined this component:

// components/buy-functions.js
export default Ember.Mixin.create({
    actions: {
        openModal: function() {
            $('#buyModal').openModal();
        }
    }
});

then in the route's template:

<h5>Buy form</h5>
{{#buy-functions}}
    <div class="btn" {{action "openModal"}}>Buy</div>
{{/buy-functions}}

(the component does not have a template)

But when i click the button I get the error "nothing handled the "openModal" action... Can someone explain what I'm doing wrong here?

Majid

You need to send your action to route

 openModal: function(modalName) {
          this.sendAction('openModal',modalName);
            }
        }

change your button to

<div class="btn" {{action "openModal" 'myModal'}}>Buy</div>

and then in your route

openModal: function(modalName) {
            //do whatever you want 
        }

But another way would be:

let's change your component to

// components/buy-functions.js
export default Ember.Component.extend({
    actions: {
        openModal: function() {
            $('#buyModal').openModal();
        }
    }
});

then create your component template

 // tempaltes/components/buy-functions.hbs
    <div class="btn" {{action "openModal"}}>Buy</div>

and then in your route template only use your component name

{{buy-functions}}

I wrote these codes on the fly. hope it works for you.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Sending action from component to route in ember.js

From Dev

Can an Ember component listen for a route's didTransition action?

From Dev

Ember Component Action Not Bubbling

From Dev

How to handle action "sent" by Ember component in wrapping view or view's controller?

From Dev

Call action from parent component in Ember 2.x

From Dev

Ember nested component action not bubbling

From Dev

Trigger route action from component

From Dev

setting model from action in ember route

From Dev

Trigger Ember Error Substate in Route Action

From Dev

Can we route from a component in ember js?

From Dev

Get current route's model in Ember component

From Dev

Ember: Bubble action from component to application controller

From Dev

Calling controller action from Ember 2.0 component

From Dev

Ember: send action from one component to another

From Dev

Access jquery event from ember component action

From Dev

Ember: send action from one component to another

From Dev

Access jquery event from ember component action

From Dev

Ember: globally-available search component (and action)?

From Dev

Ember component function outside of action function

From Dev

Ember - How to get route model inside route action

From Dev

How to programatically add component via controller action in ember 2.x

From Dev

Sending an action from a sub component to parent component in Ember 2.2

From Dev

In Ember, how do I create a component that reacts to the action of another component?

From Dev

In an Ember route how can I check if an action exists?

From Dev

Ember.js action bubbles up and skips a route

From Dev

Trigger action on controller from route after model has resolved in Ember

From Dev

Get an ember component to maintain state across route transitions

From Dev

Actions not bubbling up from Component to Route (Ember 1.13)

From Dev

Get an ember component to maintain state across route transitions

Related Related

  1. 1

    Sending action from component to route in ember.js

  2. 2

    Can an Ember component listen for a route's didTransition action?

  3. 3

    Ember Component Action Not Bubbling

  4. 4

    How to handle action "sent" by Ember component in wrapping view or view's controller?

  5. 5

    Call action from parent component in Ember 2.x

  6. 6

    Ember nested component action not bubbling

  7. 7

    Trigger route action from component

  8. 8

    setting model from action in ember route

  9. 9

    Trigger Ember Error Substate in Route Action

  10. 10

    Can we route from a component in ember js?

  11. 11

    Get current route's model in Ember component

  12. 12

    Ember: Bubble action from component to application controller

  13. 13

    Calling controller action from Ember 2.0 component

  14. 14

    Ember: send action from one component to another

  15. 15

    Access jquery event from ember component action

  16. 16

    Ember: send action from one component to another

  17. 17

    Access jquery event from ember component action

  18. 18

    Ember: globally-available search component (and action)?

  19. 19

    Ember component function outside of action function

  20. 20

    Ember - How to get route model inside route action

  21. 21

    How to programatically add component via controller action in ember 2.x

  22. 22

    Sending an action from a sub component to parent component in Ember 2.2

  23. 23

    In Ember, how do I create a component that reacts to the action of another component?

  24. 24

    In an Ember route how can I check if an action exists?

  25. 25

    Ember.js action bubbles up and skips a route

  26. 26

    Trigger action on controller from route after model has resolved in Ember

  27. 27

    Get an ember component to maintain state across route transitions

  28. 28

    Actions not bubbling up from Component to Route (Ember 1.13)

  29. 29

    Get an ember component to maintain state across route transitions

HotTag

Archive