In Aurelia, can a slot be used in a repeat.for binding?

微笑、不失礼 提交于 2019-12-07 11:15:00

问题


I'd like to create a custom element that loops through an array and applies the to each item in the array. For example, the view template of the custom element would contain something like:

<div repeat.for="i of items">
  <div with.bind="i">
    <slot></slot>
  </div>
</div>

When I remove the repeat.for and with.bind attributes, the slot displays a single time. Is there a way to make it repeat for each item in the list?


回答1:


No, you cannot use slots with repeat.for or bind today. To do this you have to use replaceable parts. For example:

<div repeat.for="i of items">
  <div with.bind="i">
    <template replaceable part="content"></template>
  </div>
</div>

Usage:

<my-component>
  <template replace-part="content">Some Content - ${somePropertyOfI}</template>
</my-component>

Runnable example: https://gist.run/?id=29aa1c1199f080c9ba0e72845044799b



来源:https://stackoverflow.com/questions/44402632/in-aurelia-can-a-slot-be-used-in-a-repeat-for-binding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!