EmberJS – Sharing Component Data with Wrapped Content

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

Description

You can share the component data with its wrapped content. Consider we have one component called {{my-component}} for which we can provide style property to write the post. You can write as โˆ’

{{#my-component editStyle="markdown-style"}}

The component is provided with the hash and supplied to the template. The editStyle can be used as an argument to the component helper.

Example

The below example specifies sharing the component data with its wrapped content. Create a component with the name post-action which will get define under app/components/.

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

import Ember from 'ember';

export default Ember.Component.extend({
   actions: {
      compFunc: function () {
         this.set('title', "Adglob...");
         //this method sends the specified action
         this.sendAction();
      }
   }
});

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

<input type="button" value="Click me" {{action "compFunc" bodyStyle="compact-style"}} /><br/>
//wrapping the 'title' property value
<p><b>Title:</b> {{title}}</p>
{{yield}}

Open the index.hbs file and add the below code:

<b>Click the button to check title property value</b>
{{post-action title=title action="compFunc"}}
{{outlet}}

Previous Page:-Click Here

This Post Has One Comment

Leave a Reply