Skip to content

Instantly share code, notes, and snippets.

@len-ro
Last active September 10, 2016 13:58
Show Gist options
  • Save len-ro/de96276009e1bfb62feba7d7bb0582cc to your computer and use it in GitHub Desktop.
Save len-ro/de96276009e1bfb62feba7d7bb0582cc to your computer and use it in GitHub Desktop.
Dynamic with compose (simple)
<template>
<button type="button" click.delegate="load($event)">Load</button>
</template>
import {inject} from 'aurelia-framework';
import {Container} from 'aurelia-dependency-injection';
import {CompositionEngine, ViewSlot, ViewResources} from 'aurelia-templating';
@inject(Container, CompositionEngine, ViewResources)
export class BasicUse {
constructor(container:Container, compositionEngine:CompositionEngine, viewResources:ViewResources){
this.compositionEngine = compositionEngine;
this.instruction = {
container: container,
viewResources: viewResources,
currentController: null
};
}
load(e){
$('button').after('<div class="inplace"></div>');
let wrapper = $('.inplace')[0];
let vSlot = new ViewSlot(wrapper, true);
this.instruction = Object.assign(this.instruction, {viewModel: 'm1', host: wrapper, viewSlot: vSlot});
this.compositionEngine.compose(this.instruction).then(controller => {
vSlot.bind();
vSlot.attached();
});
}
}
<!doctype html>
<html>
<head>
<title>Aurelia KendoUI bridge</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2016.1.226/styles/kendo.common.min.css">
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2016.1.226/styles/kendo.rtl.min.css">
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2016.1.226/styles/kendo.default.min.css">
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2016.1.226/styles/kendo.mobile.all.min.css">
<script src="https://kendo.cdn.telerik.com/2016.1.226/js/jszip.min.js"></script>
</head>
<body aurelia-app="main">
<h1>Loading...</h1>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.6/system.js"></script>
<script src="https://rawgit.com/aurelia-ui-toolkits/aurelia-kendoui-bundles/0.3.5/config2.js"></script>
<script>
System.import('aurelia-bootstrapper');
</script>
</body>
</html>
<template>
Value ${value} <button type="button" click.delegate="inc($event)">Inc</button>
</template>
export class M1 {
value = 1;
inc(e){
++this.value;
}
}
export function configure(aurelia) {
aurelia.use
.standardConfiguration()
.developmentLogging()
.plugin('aurelia-kendoui-bridge', kendo => kendo.pro());
aurelia.start().then(a => a.setRoot());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment