# Attached and repeat.for lifecycle

**URL:** <https://discourse.aurelia.io/t/attached-and-repeat-for-lifecycle/1707>\
**Category:** Help Requests\
**Created:** [October 8, 2018, 5:17pm UTC](https://discourse.aurelia.io/t/attached-and-repeat-for-lifecycle/1707 "2018-10-08T17:17:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![codedbypaul](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/codedbypaul/32/674_2.png) [@codedbypaul](https://discourse.aurelia.io/u/codedbypaul)\
**Post date:** [October 8, 2018, 5:17pm UTC](https://discourse.aurelia.io/t/attached-and-repeat-for-lifecycle/1707/1 "2018-10-08T17:17:15Z")

</div>

So i’m trying to get my head around when attached() gets called if there’s a repeater in the template.

E.g.

```
<div class="parent">
     <p repeat.for="thing of things">${thing}</p>
</div>

```

Now in attached:

```
attached() {
    const parent = document.querySelector('.parent');
    console.log(parent.offsetWidth);
}

```

Width will always be 0. If i wrap it in a setTimeout of 0 seconds then it’ll be the correct width.

Is there a way to make sure the repeated elements have rendered fully before any functions in attached() run?

---

<div class="post-metadata">

**Author:** ![huochunpeng](https://avatars.discourse-cdn.com/v4/letter/h/49beb7/32.png) [@huochunpeng](https://discourse.aurelia.io/u/huochunpeng)\
**Post date:** [October 8, 2018, 9:56pm UTC](https://discourse.aurelia.io/t/attached-and-repeat-for-lifecycle/1707/2 "2018-10-08T21:56:08Z")

</div>

This is a common issue in current Aurelia, parent element `attached` is called before child element `attached`. So in your container element `attached`, those repeat child elements were not yet populated. setTimeout is the way to fix that.

In Aurelia vNext, Rob changed the design of lifecycle callbacks, there are `attaching` and `attached` callbacks. The new `attached` will work as expected, parent element `attached` is called **after** child element `attached`.

---

<div class="post-metadata">

**Author:** ![codedbypaul](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/codedbypaul/32/674_2.png) [@codedbypaul](https://discourse.aurelia.io/u/codedbypaul)\
**Post date:** [October 9, 2018, 9:06am UTC](https://discourse.aurelia.io/t/attached-and-repeat-for-lifecycle/1707/3 "2018-10-09T09:06:17Z")

</div>

Ok. I’ve used setTimeout before but wanted to make sure there wasn’t an official way. 🙂

Thanks.
