Skip to content

Instantly share code, notes, and snippets.

@AshleyGrant
Created July 21, 2017 01:35
Show Gist options
  • Save AshleyGrant/6f9bd949ce5db6dbe45bcfb6f8ef548f to your computer and use it in GitHub Desktop.
Save AshleyGrant/6f9bd949ce5db6dbe45bcfb6f8ef548f to your computer and use it in GitHub Desktop.
Aurelia Gist
<template>
<require from="./my-custom-element"></require>
<my-custom-element name.bind="myName" class="my-class" data-id="1" />
</template>
export class App {
myName = 'Ashley';
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js" crossorigin="anonymous"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
</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>
<template>
<input ref="myInput" value.bind="name" type="text" />
</template>
import {inject, customElement, bindable} from 'aurelia-framework';
@customElement('my-custom-element')
@inject(Element)
export class MyCustomElement {
@bindable name;
constructor(el) {
this.el = el;
}
attached() {
const attributes = this.el.attributes;
for( const attr of attributes ) {
let {name, value} = attr;
if(name != 'au-target-id') {
const dotLocation = name.indexOf('.');
if( dotLocation > -1 ) {
name = name.substring(0, dotLocation);
}
if(name !== 'name') {
this.myInput.setAttribute(name,value);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment