Skip to content

Instantly share code, notes, and snippets.

@martonsagi
Forked from jdanyow/app.html
Last active January 13, 2017 16:04
Show Gist options
  • Save martonsagi/b23bf709d98b3bd3ae427852f104c890 to your computer and use it in GitHub Desktop.
Save martonsagi/b23bf709d98b3bd3ae427852f104c890 to your computer and use it in GitHub Desktop.
Aurelia Compose view-model.ref
<template>
<require from="./custom-component"></require>
<require from="./body-component"></require>
<require from="./footer-component"></require>
<h1>${message}</h1>
<body-component>
<compose view-model="./custom-component" view-model.ref="customVM"></compose>
</body-component>
<footer-component>
<button if.bind="customVM.currentViewModel.canSave">So you think you can save now?</button>
</footer-component>
</template>
export class App {
message = 'Hello World!';
attached() {
console.log("This should be a 'Compose' instance", this.customVM);
}
}
<template>
<div><strong>Body Component</strong></div>
<hr>
<div>
<slot></slot>
</div>
<hr>
</template>
export class BodyComponent {
}
<template>
<div>
My Custom Component
<br>
<label><input type="checkbox" checked.bind="controlFlag"> Check to set 'canSave=true'</label>
</div>
</template>
import { observable, computedFrom } from 'aurelia-framework';
export class CustomComponent {
@observable
controlFlag = false;
get canSave() {
return this.controlFlag;
}
controlFlagChanged() {
console.log(this.canSave);
}
}
<!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://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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment