# The element instance is not working as expected in nested custom elements

**URL:** <https://discourse.aurelia.io/t/the-element-instance-is-not-working-as-expected-in-nested-custom-elements/3826>\
**Category:** vNext\
**Created:** [October 8, 2020, 12:38pm UTC](https://discourse.aurelia.io/t/the-element-instance-is-not-working-as-expected-in-nested-custom-elements/3826 "2020-10-08T12:38:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vipinrt](https://avatars.discourse-cdn.com/v4/letter/v/ecd19e/32.png) [@vipinrt](https://discourse.aurelia.io/u/vipinrt)\
**Post date:** [October 8, 2020, 12:38pm UTC](https://discourse.aurelia.io/t/the-element-instance-is-not-working-as-expected-in-nested-custom-elements/3826/1 "2020-10-08T12:38:31Z")

</div>

We have implemented the component using nested custom elements. We are populating the data based on these custom elements and finally initializing a javascript plugin using these data. Now the plugin initialization fails due to the element reference. When we remove the child elements, it’s working as expected. There is no view(.html) for the custom elements. Please provide a solution.

**custom element usage**

```
<parent-element foo.bind="foo">
    <child-element foo1.bind="foo1"></child-element>
    <child-element foo1.bind="foo2"></child-element>
</parent-element>

```

**parent-element.ts**

import { customElement, children, inject } from ‘aurelia’;

@customElement(`parent-element`)  
@inject(Element)  
public class ParentElement {  
@children({ property: `child-element` }) childElements: any[] = [];  
element: any;  
constructor(element) {  
this.element = element;  
}  
afterAttach() {  
$(this.element).plugin({});  
}  
}

**child-element.ts**

```
import { customElement, inject } from 'aurelia';

@customElement(`child-element`)
@inject(Element)
public class ChildElement {
    
}
```

---

<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:** [October 8, 2020, 12:55pm UTC](https://discourse.aurelia.io/t/the-element-instance-is-not-working-as-expected-in-nested-custom-elements/3826/2 "2020-10-08T12:55:49Z")

</div>

The example code looks simple, so im quite confident it should work without issues. Though it would be good if you could help give a reproduction of the issue at [https://gist.dumber.app](https://gist.dumber.app)  
It will make it easier to work out the error.
