Lit-element: Conditional dom-if inside dom repeat

Created on 18 May 2018  路  3Comments  路  Source: Polymer/lit-element

So, I try to make something like this

some-element.js

<dom-repeat items="${cards}" as="item">
  <template>
    <dom-if if="${_isRoyal(item.type)}">
      <template>
        <p>The card is a Royal card!<p>
      </template>
    </dom-if>
  <template>
<dom-repeat>

...
_isActive(e) {
  console.log(e);
}
...

when I do that, the item inside <dom-if if="${_isRoyal(item.type)}"> is not defined.
and when I do this:

<dom-if if="[[_isRoyal(item.label)]]">

for the conditional part, console says that method '_isRoyal' not defined.
any help with this? thanks.

Most helpful comment

<dom-if> and <dom-repeat> are Polymer-specific concepts, not applicable to lit-html. Instead, use regular JavaScript statements to achieve the same. For example, instead of <dom-if>, use an if-statement. Instead of <dom-repeat>, you can use repeat. For more information, see https://polymer.github.io/lit-html/guide/writing-templates.html#conditionals-ifs-and-loops

All 3 comments

<dom-if> and <dom-repeat> are Polymer-specific concepts, not applicable to lit-html. Instead, use regular JavaScript statements to achieve the same. For example, instead of <dom-if>, use an if-statement. Instead of <dom-repeat>, you can use repeat. For more information, see https://polymer.github.io/lit-html/guide/writing-templates.html#conditionals-ifs-and-loops

that was helping. thanks a lot.

I'm figuring this out too, thanks.

Was this page helpful?
0 / 5 - 0 ratings