Skip to content

Instantly share code, notes, and snippets.

@oneillci
Last active October 11, 2017 01:17
Show Gist options
  • Save oneillci/7e86f9e8f98626c8e44dc22a22d99c33 to your computer and use it in GitHub Desktop.
Save oneillci/7e86f9e8f98626c8e44dc22a22d99c33 to your computer and use it in GitHub Desktop.
Inheritance problem
<template>
<require from="./my-control"></require>
<require from="./my-other"></require>
<h1>${message}</h1>
<my-control></my-control>
<br/>
<my-other></my-other>
</template>
export class App { message = 'Hello World'; }
import {inject} from "aurelia-framework";
import {Service} from "./service";
@inject(Service)
export class Base {
selectedItem: any;
service;
constructor(service) {
console.log("base constructor", this);
this.service = service;
}
created() {
console.log("Created in base")
console.log(this.service.getStuff());
}
}
<!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 {Base} from "./base";
import {bindable, inlineView, inject} from "aurelia-framework";
import {Service} from "./service";
@inject(Service)
@inlineView(`
<template>
my-control: <input type="text" value.bind="name" />
<div repeat.for="i of items" click.trigger="clicked(i)">\${i}</div>
</template>
`)
export class MyControl extends Base {
@bindable items = [1, 2, 3];
@bindable selectedItem;
name = "ciaran";
service;
constructor(service) {
super(service);
this.service = service;
}
created() {
super.created();
console.log("created in my control", this.items, this.name)
}
selectedItemChanged() {
console.log("mycontrol selected item is", this.selectedItem);
}
clicked(i){
console.log(i);
this.selectedItem = i;
console.log(this.service.getStuff());
}
}
import {Base} from "./base";
import {bindable, inlineView, inject} from "aurelia-framework";
import {Service} from "./service";
@inject(Service)
@inlineView(`
<template>
my-other: <input type="text" value.bind="name" />
<div repeat.for="i of items" click.trigger="clicked(i)">\${i}</div>
</template>
`)
export class MyOther extends Base {
@bindable items = [6,7,8];
@bindable selectedItem;
name = "poppy";
service;
constructor(service) {
super(service);
this.service = service;
}
created() {
super.created();
console.log("created in my other", this.items, this.name)
}
selectedItemChanged() {
console.log("myother selected item is", this.selectedItem);
}
clicked(i){
console.log(i);
this.selectedItem = i;
console.log(this.service.getStuff());
}
}
export class Service {
getStuff() {
return [9,0,8];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment