Skip to content

Instantly share code, notes, and snippets.

@ZoolWay
Last active August 18, 2017 14:42
Show Gist options
  • Save ZoolWay/928f97f49c01c1db10d8bf4399f5c335 to your computer and use it in GitHub Desktop.
Save ZoolWay/928f97f49c01c1db10d8bf4399f5c335 to your computer and use it in GitHub Desktop.
Getting view model of containerless custom element
<template>
<require from="norm-comp"></require>
<require from="less-comp"></require>
<require from="list-comp"></require>
<h1>Getting view model of containerless custom element</h1>
<list-comp>
<norm-comp text="item one, normal"></norm-comp>
<norm-comp text="item two, normal"></norm-comp>
<less-comp view-model.ref="lessVmRef" text="item three, containerless"></less-comp>
</list-comp>
</template>
import { bindable, observable } from 'aurelia-framework'
export class App {
lessVmRef = null;
attached() {
console.info(`Attached, less-vm-ref:`, this.lessVmRef);
}
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body aurelia-app>
<h1>Loading...</h1>
<script src="https://jdanyow.github.io/rjs-bundle/node_modules/requirejs/require.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/config.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/bundles/babel.js"></script>
<script>
require(['aurelia-bootstrapper']);
</script>
</body>
</html>
<template>
<li>${text}</li>
</template>
import { bindable, containerless } from 'aurelia-framework'
@containerless
export class LessComp {
@bindable text = null;
created(owningView, view) {
console.log('view of less-comp:', view);
}
constructor() {
}
activate(model) {
}
attached() {
}
detached() {
}
}
<template>
<ul ref="listContainer">
<slot></slot>
</ul>
</template>
import { bindable, children, containerless } from 'aurelia-framework'
export class ListComp {
@children('*') domItems = null;
listContainer = null;
attached() {
console.info('Got children:', this.domItems);
console.info('List container:', this.listContainer);
for (let i = 0; i < this.listContainer.children.length; i++) {
let c = this.listContainer.children[i];
console.info(`Child #${i}, au = `, c.au);
}
}
detached() {
}
}
<template>
<li>norm: ${text}</li>
</template>
import { bindable } from 'aurelia-framework'
export class NormComp {
@bindable text = null;
constructor() {
}
activate(model) {
}
attached() {
}
detached() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment