Samuel Segal
Samuel Segal

Reputation: 423

Sending parameter to a component property

I understand how to send parameters along with an action to a component:

http://emberjs.com/guides/components/sending-actions-from-components-to-your-application/

Is there a way to send parameters to a component's property?

Example: In a template, I'm rendering a component inside an each loop. The loop is iterating through the various instances of the model of the array controller. I would like to pass the individual instance of the model of the array controller to a property of the component. The property is a function that will create a chart base on the value of the passed instance of the model. The chart needs to be created in JavaScript. Any way to achieve this?

Upvotes: 0

Views: 1619

Answers (2)

dpdawson
dpdawson

Reputation: 488

I would pass in the model as a regular property and then call the chart creating function on the didInsertElement event.

http://emberjs.com/api/classes/Ember.Component.html#event_didInsertElement

Upvotes: 1

Kalman
Kalman

Reputation: 8121

If I understand what you are asking - this is actually very easy to accomplish:

http://emberjs.com/guides/components/passing-properties-to-a-component/

So, something like the following:

{{ your-component propertyInComponent=modelInstance }}

Then, in your propertyInComponent which is defined in your component's js file is yours to do whatever you want with it.

Upvotes: 2

Related Questions