Skip to content

Instantly share code, notes, and snippets.

@plwalters
Created February 21, 2017 07:55
Show Gist options
  • Select an option

  • Save plwalters/7e13935962a20b8518f4fc4548240bf4 to your computer and use it in GitHub Desktop.

Select an option

Save plwalters/7e13935962a20b8518f4fc4548240bf4 to your computer and use it in GitHub Desktop.
Binding custom attribute
<template>
<h1>${message}</h1>
<p attributes.bind="attributes">Inspect me.</p>
</template>
import {bindable} from 'aurelia-framework';
export class App {
@bindable attributes = {foo: 'bar'};
message = 'Hello World!';
}
import {dynamicOptions, inject, customAttribute, bindable} from 'aurelia-framework';
@dynamicOptions
@inject(Element)
@customAttribute('attributes')
export class Attributes {
@bindable attributes;
constructor(element) {
this.element = element;
}
propertyChanged(name, newValue) {
this.element.setAttribute(name, newValue);
}
}
<!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('attributes');
aurelia.start().then(a => {
a.setRoot('app');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment