Skip to content

Instantly share code, notes, and snippets.

@opcodewriter
Last active April 30, 2016 09:36
Show Gist options
  • Save opcodewriter/d8611c0f864e9017c05f37e30cd6c004 to your computer and use it in GitHub Desktop.
Save opcodewriter/d8611c0f864e9017c05f37e30cd6c004 to your computer and use it in GitHub Desktop.
Aurelia parent vm in child vm
<template>
<require from="./parent"></require>
<parent name='a'></parent>
<parent name='b'></parent>
<parent></parent>
</template>
export class App {
}
<template>
<button>button from child</button>
</template>
import {inject} from 'aurelia-framework';
import {Parent} from './parent'
@inject(Parent)
export class Child {
//static inject = [Parent];
constructor(parent) {
this.parent = parent;
console.log("hello from child, parent's name is", this.parent.name);
}
}
<!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>
<template>
<require from="./child"></require>
<div>Hello</div>
<child></child>
</template>
import {bindable, inject} from 'aurelia-framework';
export class Parent {
constructor() {}
@bindable name;
nameChanged(newValue) {
console.log("name changed:", this.name);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment