Skip to content

Instantly share code, notes, and snippets.

@qtuan
Last active September 26, 2016 13:45
Show Gist options
  • Save qtuan/d7d48f1ff702a635682f17b4fd7fb2da to your computer and use it in GitHub Desktop.
Save qtuan/d7d48f1ff702a635682f17b4fd7fb2da to your computer and use it in GitHub Desktop.
Aurelia custom element inheritance
<template>
<require from="./thing"></require>
<require from="./child-thing"></require>
<require from="./other-thing"></require>
<thing></thing>
<child-thing></child-thing>
<other-thing></other-thing>
</template>
export class App {
}
import {Thing} from './thing';
import {useView} from 'aurelia-framework';
@useView('./thing.html')
export class ChildThing extends Thing { // extends do not work?
// setContent() {
// this.content = 'A child thing';
// }
// attached() {
// this.content = 'A child thing';
// }
}
<!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>
import {useView} from 'aurelia-framework';
@useView('./thing.html')
export class OtherThing {
content = 'Some other thing';
}
<template>
<div>${content}</div>
</template>
export class Thing {
attached() {
this.setContent();
}
setContent() {
this.content = 'A thing';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment