Skip to content

Instantly share code, notes, and snippets.

@jdanyow
Created April 26, 2016 20:30
Show Gist options
  • Save jdanyow/b075366d29f2400d3cc931f6fc26db24 to your computer and use it in GitHub Desktop.
Save jdanyow/b075366d29f2400d3cc931f6fc26db24 to your computer and use it in GitHub Desktop.
<template>
<require from="./thing"></require>
<thing name="A">
<thing name="B">
<thing name="C">
<thing name="D">
</thing>
</thing>
</thing>
</thing>
</template>
export class App {
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
thing {
display: block;
border: 1px solid blue;
padding: 5px 5px;
}
</style>
</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>
import {resolver} from 'aurelia-dependency-injection';
@resolver()
export class OptionalParent {
constructor(key) {
this.key = key;
}
get(container) {
if (container.parent && container.parent.hasResolver(this.key, false)) {
return container.parent.get(this.key)
}
return null;
}
static of(key) {
return new OptionalParent(key);
}
}
<template>
<h3>
My Name is "${name}".
<span if.bind="parent">My parent's name is "${parent.name}".</span>
<span if.bind="!parent">I don't have a parent.</span>
</h3>
<content></content>
</template>
import {bindable, inject} from 'aurelia-framework';
import {OptionalParent} from './optional-parent';
@inject(OptionalParent.of(Thing))
export class Thing {
@bindable name;
constructor(parent) {
this.parent = parent;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment