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

Jonathan

Hi I'm trying to send an action from a sub component back up to the parent component so it can access this.store and perform a DB action. The basic layout is this:

app/templates/item/index.hbs -> does a loop of items using component

            {{#each model as |item|}}
                {{item-listing item=item}}
            {{/each}}

app/templates/components/item-listing.hbs

<li><a {{action 'copyItem' item}}>Copy</a></li>

In app/components/item-listing.js I have to define an action or I get an action not defined error. From here this.store is undefined, so I'm trying to bubble the action up.

actions: {
    copyItem: function(item) {
        this.sendAction('copyItem', item);
    },

From here I'm lost. I've tried putting actions on all of the following:

/app/routes/item/index.js /app/routes/item.js

But it never seems to get past the sendAction call. What am I doing wrong?

Daniel Kmak

You have to:

  1. Define that action (copyItem) in your controller (ItemIndexController).
  2. Pass that action in template loop:

1st way:

{{#each model as |item|}}
    {{item-listing item=item copyItem='copyItem'}}
{{/each}}

2nd way:

{{#each model as |item|}}
    {{item-listing item=item copyItem=(action 'copyItem')}}
{{/each}}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Call action from parent component in Ember 2.x

From Dev

Sending action to parent component Angular2

From Dev

Ember 2 action sent to route instead of component

From Dev

Sending action from component to route in ember.js

From Dev

Angular2 Routing - Passing data from parent component to a sub-child component

From Dev

Angular 2: getting RouteParams from parent component

From Dev

angular 2 access child component property from parent component

From Dev

calling parent component function from router component in angular2

From Java

Update parent component property from child component in Angular 2

From Dev

Angular 2, How to pass options from parent component to child component?

From Dev

Update parent component title from routed child component in Angular 2

From Dev

how to update parent component from child component in angular2

From Dev

Angular2 - Trying to add a component into a child component from parent

From Dev

Angular 2 Parent Component Losing Input Binding from Child 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 Component Action Not Bubbling

From Dev

How to set Ember component's internal state from parent component?

From Dev

Angular 2 ES6 - Sending event from component

From Dev

Angular 2 ES6 - Sending event from component

From Dev

Sending whole object from one component to another in angular 2

From Dev

Angular 2 - Routing from the `first child` component to a `second child` component of a parent component

From Dev

Angular 2 - Routing from the `first child` component to a `second child` component of a parent component

From Dev

EmberJS trigger action on parent component from child

From Dev

ember.js | How to bind an event of a sub-component to an action of an outer component

Related Related

  1. 1

    Call action from parent component in Ember 2.x

  2. 2

    Sending action to parent component Angular2

  3. 3

    Ember 2 action sent to route instead of component

  4. 4

    Sending action from component to route in ember.js

  5. 5

    Angular2 Routing - Passing data from parent component to a sub-child component

  6. 6

    Angular 2: getting RouteParams from parent component

  7. 7

    angular 2 access child component property from parent component

  8. 8

    calling parent component function from router component in angular2

  9. 9

    Update parent component property from child component in Angular 2

  10. 10

    Angular 2, How to pass options from parent component to child component?

  11. 11

    Update parent component title from routed child component in Angular 2

  12. 12

    how to update parent component from child component in angular2

  13. 13

    Angular2 - Trying to add a component into a child component from parent

  14. 14

    Angular 2 Parent Component Losing Input Binding from Child Component

  15. 15

    Ember: Bubble action from component to application controller

  16. 16

    Calling controller action from Ember 2.0 component

  17. 17

    Ember: send action from one component to another

  18. 18

    Access jquery event from ember component action

  19. 19

    Ember: send action from one component to another

  20. 20

    Access jquery event from ember component action

  21. 21

    Ember Component Action Not Bubbling

  22. 22

    How to set Ember component's internal state from parent component?

  23. 23

    Angular 2 ES6 - Sending event from component

  24. 24

    Angular 2 ES6 - Sending event from component

  25. 25

    Sending whole object from one component to another in angular 2

  26. 26

    Angular 2 - Routing from the `first child` component to a `second child` component of a parent component

  27. 27

    Angular 2 - Routing from the `first child` component to a `second child` component of a parent component

  28. 28

    EmberJS trigger action on parent component from child

  29. 29

    ember.js | How to bind an event of a sub-component to an action of an outer component

HotTag

Archive