Skip to content

Instantly share code, notes, and snippets.

@plwalters
Last active March 17, 2017 05:14
Show Gist options
  • Save plwalters/9c0053625209e0ff7fe87e5fa2574862 to your computer and use it in GitHub Desktop.
Save plwalters/9c0053625209e0ff7fe87e5fa2574862 to your computer and use it in GitHub Desktop.
DI inheritance
<template>
<require from="./child-element"></require>
<require from="./child-element-two"></require>
<h2>Parent Errors below</h2>
<ul>
<li repeat.for="error of errors">
${error.name}
</li>
</ul>
<child-element></child-element>
<child-element-two></child-element-two>
</template>
export class App {
errors = [];
}
<template>
<h2>Child Two Errors below</h2>
<ul>
<li repeat.for="error of errors">
${error.name}
</li>
</ul>
<button click.delegate="addError()">Add Error From Child</button>
</template>
import {bindable} from 'aurelia-framework';
import {App} from './app';
export class ChildElementTwo {
@bindable errors = [];
static inject = [App];
constructor(app) {
this.app = app;
}
addError() {
let newError = new ErrorItem();
this.errors.push(newError);
this.app.errors.push(newError);
}
}
class ErrorItem {
name = '';
constructor() {
this.name = 'Error two';
}
}
<template>
<h2>Child One Errors below</h2>
<ul>
<li repeat.for="error of errors">
${error.name}
</li>
</ul>
<button click.delegate="addError()">Add Error From Child</button>
</template>
import {bindable} from 'aurelia-framework';
import {App} from './app';
export class ChildElement {
@bindable errors = [];
static inject = [App];
constructor(app) {
this.app = app;
}
addError() {
let newError = new ErrorItem();
this.errors.push(newError);
this.app.errors.push(newError);
}
}
class ErrorItem {
name = '';
constructor() {
this.name = 'Error one';
}
}
<!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://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/jspm_packages/system.js"></script>
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/config.js"></script>
<script>
System.import('aurelia-bootstrapper');
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment