Last active
August 18, 2017 14:42
-
-
Save ZoolWay/928f97f49c01c1db10d8bf4399f5c335 to your computer and use it in GitHub Desktop.
Getting view model of containerless custom element
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { bindable, observable } from 'aurelia-framework' | |
export class App { | |
lessVmRef = null; | |
attached() { | |
console.info(`Attached, less-vm-ref:`, this.lessVmRef); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<li>${text}</li> | |
</template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<ul ref="listContainer"> | |
<slot></slot> | |
</ul> | |
</template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<li>norm: ${text}</li> | |
</template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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