EmberJS – Defining a Component

  • Post author:
  • Post category:EmberJS
  • Post comments:1 Comment
Define

You can easily define the component in Ember.js and each component must have a dash in their name (ex: my-component). Ember.js has the power of defining the component subclasses by using an Ember.Component class.

The component can be created by using the below command โˆ’

ember generate component component-name

Example

The example given below describe how to define a component in Ember.js. Create a component with the name post-action, which will get defined under app/components/.

Open the post-action.js file and add the following code โˆ’

import Ember from 'ember';

export default Ember.Component.extend ({
   toggleBody:['Welcome to Adglob!!!']
});

Now open the component template file post-action.hbs with the following code โˆ’

{{#each toggleBody as |body|}}
   Hello...{{body}}
{{/each}}
{{yield}}

Open the index.hbs file and add the following code โˆ’

{{post-action}}
{{outlet}}

Previous Page:-Click Here

This Post Has One Comment

Leave a Reply