Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember components without wrapping in .ember-view class?

Tags:

ember.js

I am trying to create a component for a carousel but if I iterate through the HTML with Ember components it wraps each slide with which breaks the structure of the html.

It should be:

<div class="banner">
    <ul>
        <li>This is a slide.</li>
        <li>This is another slide.</li>
        <li>This is a final slide.</li>
    </ul>
</div>

But it turns into:

<div class="banner">
    <ul>
        <div class="ember-view">
            <li>This is a slide.</li>
        </div>
        <div class="ember-view"> 
            <li>This is another slide.</li>
        </div>
        <div class='ember-view'>
            <li>This is a final slide.</li>
        </div>
    </ul>
</div>

How do you solve this?

Are components the wrong thing to use for this?

like image 756
Daniel Fischer Avatar asked Sep 30 '13 20:09

Daniel Fischer


1 Answers

Modify the tagName of the component:

App.CarouselSlideComponent = Ember.Component.extend({
  tagName: 'li'
});

Usage:

<ul>
  {{#each slides}}
    {{#carousel-slide}}
      {{content}}
    {{/carousel-slide}}
  {{/each}}
</ul>

Or pass it inline:

<ul>
  {{#each slides}}
    {{#carousel-slide tagName="li"}}
      {{content}}
    {{/carousel-slide}}
  {{/each}}
</ul>
like image 82
Panagiotis Panagi Avatar answered Nov 15 '22 10:11

Panagiotis Panagi