lit: Using repeat directive is not working
Hi, I created this code snippet
const items = [
{
id: 0,
label: 'Hey'
},
{
id: 1,
label: 'Hey'
}
];
const template = (self) => html`
<nav class="header-navigation">
<ul class="navigation-list">
${repeat(items, (i) => i.id, (i, index) => html`
<li>${index}: ${i.label}</li>`)}
</ul>
</nav>
`;
and it returns an error
repeat.js:38 Uncaught Error: repeat can only be used on NodeParts
at part (repeat.js:38)
at getValue (element-lite.umd.js:1686)
at NodePart.setValue (element-lite.umd.js:1763)
at TemplateInstance.update (element-lite.umd.js:1909)
at NodePart._setTemplateResult (element-lite.umd.js:1822)
at NodePart.setValue (element-lite.umd.js:1775)
at TemplateInstance.update (element-lite.umd.js:1909)
at render (element-lite.umd.js:1489)
at HTMLElement.invalidate (element-lite.umd.js:2117)
at HTMLElement.connectedCallback (element-lite.umd.js:2099)
Am i doing something wrong?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 15 (7 by maintainers)
Also check your dependencies, lit-element is at version
0.5.1as of writing this. You should not need to install lit-html separately.Check out https://github.com/Polymer/pwa-starter-kit for a starter kit using LitElement. The wiki at https://github.com/Polymer/pwa-starter-kit/wiki contains many helpful demo apps with source codes.
Particularly, https://github.com/PolymerLabs/polymer-redux-hn/blob/master/src/components/hn-list.js uses
LitElementandrepeat, may be useful to study.Admittedly, going the LitElement route is unnerving and at times feels like re-inventing the wheel. (someone get me an advanced router for LitElement, anyone?) Really tempted by Vue and all that. Take your pick between magic and standards-based.
@bgotink I’m using it as part of shadow dom. I’m going to create a small repo for it.
How did you import
repeat? It should be coming fromimport {repeat} from "lit-html/lib/repeat"