# Au 2.0: Template refs with repeat.for

**URL:** <https://discourse.aurelia.io/t/au-2-0-template-refs-with-repeat-for/6559>\
**Category:** Help Requests\
**Created:** [December 23, 2025, 8:10pm UTC](https://discourse.aurelia.io/t/au-2-0-template-refs-with-repeat-for/6559 "2025-12-23T20:10:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![estaylorco](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/estaylorco/32/1887_2.png) [@estaylorco](https://discourse.aurelia.io/u/estaylorco)\
**Post date:** [December 23, 2025, 8:10pm UTC](https://discourse.aurelia.io/t/au-2-0-template-refs-with-repeat-for/6559/1 "2025-12-23T20:10:14Z")

</div>

Hello,

I’ve searched the documentation, and Discourse, and I can’t seem to find a definitive approach to template refs with a `repeat.for`.

A number of Discourse posts sort of swirl around the issue, but none seems to be working for me. I’ve hit upon this, below, but I don’t know if it’s acceptable:

```xml
...
<div repeat.for="doc of docs" ref="listOfDocs[$index]"></div>
...

```

In the view model, I get an object, not an array, that has the structure:

```javascript
{
   0: (a doc HTMLElement),
   1: (a doc HTMLElement),
   2: (a doc HTMLElement),
   ...
}

```

where each key is the index. I have a computed property that makes this object practical:

```javascript
...
get $docElements() {
  return Object.values(this.listOfDocs);
}
...

```

where `listOfDocs` is properly on the view model, as I would expect.

All of this works, and the computed property does, indeed, recompute. I just want to be sure that this approach is sound.

---

<div class="post-metadata">

**Author:** ![bigopon](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/bigopon/32/18_2.png) [@bigopon](https://discourse.aurelia.io/u/bigopon)\
**Post date:** [December 23, 2025, 11:47pm UTC](https://discourse.aurelia.io/t/au-2-0-template-refs-with-repeat-for/6559/2 "2025-12-23T23:47:46Z")

</div>

I’d probably do the same thing 🙂 , though you may end up with some `null` value in the array when the repeater collection shrinks.

---

<div class="post-metadata">

**Author:** ![estaylorco](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/estaylorco/32/1887_2.png) [@estaylorco](https://discourse.aurelia.io/u/estaylorco)\
**Post date:** [December 24, 2025, 12:57am UTC](https://discourse.aurelia.io/t/au-2-0-template-refs-with-repeat-for/6559/3 "2025-12-24T00:57:56Z")

</div>

Yeah, I figured out the `null` problem, funny you should say 🙂 . But it’s easy to defend against. Moving to a dynamic filter seemed to cause the `null` s to go away, though.

Is this a viable feature? What if we simply had this:

```xml
...
<div repeat.for="doc of docs" ref="listOfDocs"></div>
...

```

with no `$index` reference. Aurelia could automatically populate an array based on `$index` since it’s on a `repeat.for`. (Perhaps similar logic as what we have with `@children`).

---

<div class="post-metadata">

**Author:** ![bigopon](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/bigopon/32/18_2.png) [@bigopon](https://discourse.aurelia.io/u/bigopon)\
**Post date:** [December 24, 2025, 3:07am UTC](https://discourse.aurelia.io/t/au-2-0-template-refs-with-repeat-for/6559/4 "2025-12-24T03:07:51Z")

</div>

> [@estaylorco](#):
>
> ```xml
> <div repeat.for="doc of docs" ref="listOfDocs"></div>
> 
> ```

This only works if your setter does some array appending behind the scene. It wouldn’t be able to clear up the reference later though, since the value you get back to compare to decide whether the reference should be cleared isn’t the same, due to the lack of index information.

Personally I would also prefer something plain and clear on the template.
