templating: @child and @children not working on nested components

I’m submitting a bug report

  • Library Version: 1.0.1

Please tell us about your environment:

  • Operating System: Linux (Ubuntu 16.04 LTS)

  • Node Version: 5.10.1

  • NPM Version: 3.8.3

  • JSPM OR Webpack AND Version Aurelia CLI?

  • Browser: Chrome Version 51.0.2704.84 (64-bit)

  • Language: all

Current behavior: When I use @child and @children on a component inside another component I get undefined

Expected/desired behavior: I expect a reference to the child element

Here’s an example: https://gist.run/?id=923920bcb56e0e4709954c93e5bece87

Please check the console. When I try to get a reference to CustomTitle from CustomContainer I get undefined

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 36 (16 by maintainers)

Most upvoted comments

+1 for updating the docs. They just reference @child and @children briefly and they don’t even explain this selectorOrConfig property.

I think I found what was going on. I was expecting the @child property to be populated when attached() happens, but it seems that is not the case. Instead, I listen for my property to be changed. For instance, if I have: @child('my-element') myChild; Then I would listen for it on: myChildChanged(newValue, OldValue){ //My child has a value here }

So it seems to be working as expected.

I’m having the same problem, but for me they don’t work at all.

I have even tried just selecting normal element like h1 or div, and I keep getting undefined. When I inspect the generated HTML code I can clearly see that the selector I’m using is a direct children of my custom element, but never the less the property does not get synced with the elements.

This is a VERY important feature for templating, specially when you are writing plugins that need to manipulate the DOM.

It could be that we are using it wrong, and on that case we need some good examples in the documentation, because right now they are just mentioned without no examples.

The parent component needs to at least have a <slot></slot> element in its view or there’s nowhere to project the the child elements. We may be able to improve that in the future. I realize it’s a bit quirky in this case, since these elements have no view.

@ErikSchierboom Next issue is that you need a slot element in your grid view or otherwise the custom element doesn’t know where to put the column elements. I recommend just adding one below the table and then make sure to have some css that matches the column element and makes it display:none since you are using that mostly as a data element.