Skip to content

Instantly share code, notes, and snippets.

@Vheissu
Forked from jdanyow/app.html
Last active June 21, 2016 01:40
Show Gist options
  • Save Vheissu/6b9605f5f86e6212ec81da7393c1b485 to your computer and use it in GitHub Desktop.
Save Vheissu/6b9605f5f86e6212ec81da7393c1b485 to your computer and use it in GitHub Desktop.
<template>
<compose view.bind="viewStrategy" view-model.bind="viewModel" containerless></compose>
</template>
import {InlineViewStrategy} from 'aurelia-framework';
export class App {
viewHtml = '<template><my-element></my-element><h1>${message}</h1></template>';
viewModel = { message: 'hello world' };
viewStrategy;
bind() {
this.viewStrategy = new InlineViewStrategy(this.viewHtml);
}
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body aurelia-app="main">
<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>
export function configure(aurelia) {
aurelia.use
.standardConfiguration()
.developmentLogging()
.globalResources('./my-element');
aurelia.start().then(a => a.setRoot());
}
<template>
My Element
</template>
export class MyElement {
}
textarea {
display: block;
}
import {
inject,
ViewCompiler,
ViewResources,
Container,
ViewSlot,
createOverrideContext
} from 'aurelia-framework';
@inject(ViewCompiler, ViewResources, Container)
export class ViewFactory {
constructor(viewCompiler, resources, container) {
this.viewCompiler = viewCompiler;
this.resources = resources;
this.container = container;
}
insert(containerElement, html, viewModel) {
let viewFactory = this.viewCompiler.compile(html);
let view = viewFactory.create(this.container);
let anchorIsContainer = true;
let viewSlot = new ViewSlot(containerElement, anchorIsContainer);
viewSlot.add(view);
view.bind(viewModel, createOverrideContext(viewModel));
return () => {
viewSlot.remove(view);
view.unbind();
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment