Skip to content

Instantly share code, notes, and snippets.

@Vheissu
Last active December 7, 2016 05:03
Show Gist options
  • Save Vheissu/c7f914adec6ead45d01ba94ecdd8b5d5 to your computer and use it in GitHub Desktop.
Save Vheissu/c7f914adec6ead45d01ba94ecdd8b5d5 to your computer and use it in GitHub Desktop.
Aurelia code snippet custom element demo
<template>
<require from="./code-snippet"></require>
<code-snippet model.bind="{name: 'Rob', likes: ['apples', 'oranges', 'bananas', 'pineapples']}">
<h1>Hello, my name is: ${name}</h1>
<h2>My favourite fruits are:</h2>
<ul>
<li repeat.for="fruit of likes">${fruit}</li>
</ul>
</code-snippet>
</template>
export class App {
}
/**
* Code Snippet Custom Element
*
* @author Dwayne Charrington <dwaynecharrington@gmail.com>
* @copyright Dwayne Charrington 2016
*
* https://discoveraurelia.com
*
*/
import {bindable, inject, noView, processContent, TemplatingEngine} from 'aurelia-framework';
@processContent(false)
@noView
@inject(Element, TemplatingEngine)
export class CodeSnippetCustomElement {
@bindable model;
constructor(element, templatingEngine) {
this.element = element;
this.templatingEngine = templatingEngine;
}
attached() {
this.enhance();
}
enhance() {
for (let i = 0; i < this.element.children.length; i++) {
this.templatingEngine.enhance({
bindingContext: this.model,
element: this.element.children.item(i)
});
}
}
}
<!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