fvisticot
fvisticot

Reputation: 8547

Component, controller and context: wrong controller inside the component?

I'm using ember.js 1.0.RC6

I have created a component (options-carousel) and I would like to render content inside this component.

The first {{controller}}{{test}} is displaying the correct value for test from the controller.

The second {{controller}}{{test}} is displaying the OptionsCarouselComponent for the controller and nothing for the test (because it seems a bad reference to the controller).

{{controller}}{{test}}
{{#options-carousel}}
<div class="active item">
    {{controller}}{{test}}
</div>
{{/options-carousel}}

Upvotes: 2

Views: 423

Answers (1)

Mike Grassotti
Mike Grassotti

Reputation: 19050

The context inside a component is the component itself. This is by design, so that components will be isolated from surrounding context.

To access a property of your controller from within a component, pass it as an argument like:

{{controller}}{{test}}
{{#options-carousel test="test"}}
<div class="active item">
  {{controller}}{{test}}
</div>
{{/options-carousel}}

Upvotes: 3

Related Questions