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

Sachin Sharma

I am being faced with the same problem on

How to programatically add component via controller action However since I am using ember cli, I am unable to do so. Here is my source code

import Ember from "ember";
export default Ember.Component.extend({
    actions : {
        remove : function(){
            this.remove();
        },
        add : function()
        {
            Ember.AuthorNameComponent.create().appendTo($('#authors'));
        }
    },
});

When I try to run this code, I get undefined error. Also name of component is author-name.

Any help, how can I create component via programmatically?

jax

You need to import the component, then you don't need the Ember Global.

import AuthorNameComponent from '../components/author-name-component'

Another way is to have an array of items and base the list of AuthorNameComponent from that.

{{#each items as |item|}}
    {{author-name name=item.name}}
{{/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

How to programatically add component via controller action

From Dev

Call action from parent component in Ember 2.x

From Dev

Ember: Bubble action from component to application controller

From Dev

Calling controller action from Ember 2.0 component

From Dev

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

From Dev

Ember 2 action sent to route instead of component

From Dev

How to run action in Ember Controller afterRender

From Dev

Ember 2.11.X How to get the Input value of and component through the action handler

From Dev

How to programatically add constraints to a button in Swift 2?

From Dev

Ember component cannot use access controller property via "needs"

From Dev

How to route to a component programatically

From Dev

Ember Component Action Not Bubbling

From Dev

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

From Dev

Custom templateName in Ember 2.x component

From Dev

In play framework 2.x, how to add a global action/filter?

From Dev

How to send an action from a Ember component to a View that wraps it?

From Dev

How to send an action from a Ember component to a View that wraps it?

From Dev

Ember controller: nothing handled the action

From Dev

How to add a new action to the existing controller?

From Dev

Silverstripe - How to add a new action to the existing controller

From Dev

How to add JavaScript for a specific controller and action in yii

From Dev

How to add an action to the button in Controller of magento?

From Dev

Ember component test -- how unit test component's action when it doesn't invoke an external action?

From Dev

How to get the outer parent controller from inside an ember component?

From Dev

how to prevent sync of nested array object between controller and component in ember

From Dev

Ember nested component action not bubbling

From Dev

How do I toggle a classname to a component via an action in another component?

From Dev

binding controller object to a component in ember

From Dev

include bower component in Ember Controller

Related Related

  1. 1

    How to programatically add component via controller action

  2. 2

    Call action from parent component in Ember 2.x

  3. 3

    Ember: Bubble action from component to application controller

  4. 4

    Calling controller action from Ember 2.0 component

  5. 5

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

  6. 6

    Ember 2 action sent to route instead of component

  7. 7

    How to run action in Ember Controller afterRender

  8. 8

    Ember 2.11.X How to get the Input value of and component through the action handler

  9. 9

    How to programatically add constraints to a button in Swift 2?

  10. 10

    Ember component cannot use access controller property via "needs"

  11. 11

    How to route to a component programatically

  12. 12

    Ember Component Action Not Bubbling

  13. 13

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

  14. 14

    Custom templateName in Ember 2.x component

  15. 15

    In play framework 2.x, how to add a global action/filter?

  16. 16

    How to send an action from a Ember component to a View that wraps it?

  17. 17

    How to send an action from a Ember component to a View that wraps it?

  18. 18

    Ember controller: nothing handled the action

  19. 19

    How to add a new action to the existing controller?

  20. 20

    Silverstripe - How to add a new action to the existing controller

  21. 21

    How to add JavaScript for a specific controller and action in yii

  22. 22

    How to add an action to the button in Controller of magento?

  23. 23

    Ember component test -- how unit test component's action when it doesn't invoke an external action?

  24. 24

    How to get the outer parent controller from inside an ember component?

  25. 25

    how to prevent sync of nested array object between controller and component in ember

  26. 26

    Ember nested component action not bubbling

  27. 27

    How do I toggle a classname to a component via an action in another component?

  28. 28

    binding controller object to a component in ember

  29. 29

    include bower component in Ember Controller

HotTag

Archive