Skip to content

Instantly share code, notes, and snippets.

@sjarvela
Last active September 9, 2021 13:18
Show Gist options
  • Save sjarvela/fcc5ad30922a91aba364677161f3ce33 to your computer and use it in GitHub Desktop.
Save sjarvela/fcc5ad30922a91aba364677161f3ce33 to your computer and use it in GitHub Desktop.
aurelia2-compose
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dumber Gist</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
<base href="/">
</head>
<!--
Dumber Gist uses dumber bundler, the default bundle file
is /dist/entry-bundle.js.
The starting module is pointed to "main" (data-main attribute on script)
which is your src/main.js.
-->
<body>
<my-app></my-app>
<script src="/dist/entry-bundle.js" data-main="main"></script>
</body>
</html>
{
"dependencies": {
"aurelia": "latest"
}
}
import Aurelia from 'aurelia';
import { MyApp } from './my-app';
Aurelia.app(MyApp).start();
<h2>Compose</h2>
Select
<button repeat.for="item of items" click.trigger="selected = item">${item.name}</button>
<div if.bind="selected">
<span>Selected: ${selected.name}</span>
<br/>
<div style="border: 1px solid red">
<au-compose view-model.bind="selected.component" model.bind="{ name: selected.name }" />
</div>
</div>
import { MyCustomComponent } from "./my-custom-component";
import { MyCustom2Component } from "./my-custom2-component";
export class MyApp {
items = [
{ name: 'Item A', component: MyCustomComponent },
{ name: 'Item B', component: MyCustomComponent },
{ name: 'Item C', component: MyCustom2Component }
]
selected = null;
}
<div>This is custom component with name: ${name}</div>
import { bindable } from "aurelia";
export class MyCustomComponent {
@bindable
name
activate(model) {
this.name = model.name;
}
}
<div>This is another custom component with name: ${name}</div>
import { bindable } from "aurelia";
export class MyCustom2Component {
@bindable
name
activate(model) {
this.name = model.name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment