Skip to content

Instantly share code, notes, and snippets.

@djedi
Last active January 5, 2018 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djedi/80104342cc35db2e518a7461795c6bfb to your computer and use it in GitHub Desktop.
Save djedi/80104342cc35db2e518a7461795c6bfb to your computer and use it in GitHub Desktop.
get attribute from parent
<template>
<require from="./my-radio-holder"></require>
<require from="./my-radio"></require>
<my-radio-holder name="myname" id="force"> <!-- id is optional -->
<my-radio>Option 1</my-radio>
<my-radio>Option 2</my-radio>
</my-radio-holder>
</template>
export class App {
}
<!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>
<div id.bind="id"><slot></slot></div>
</template>
import {bindable, containerless} from 'aurelia-framework';
@containerless
export class MyRadioHolder {
@bindable name;
@bindable id = Math.random().toString(36).slice(-7);
attached() {
let elem = document.getElementById(this.id);
elem.childNodes.forEach((n) => {
n.name = this.name;
})
}
}
<template>
<input type="radio" id.bind="id"><slot></slot></input>
</template>
import {containerless} from 'aurelia-framework';
@containerless
export class MyRadio {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment