Skip to content

Instantly share code, notes, and snippets.

@fabioluz
Last active March 8, 2017 16:00
Show Gist options
  • Select an option

  • Save fabioluz/f7f89f35b62acb5b4f05ffe59be1880e to your computer and use it in GitHub Desktop.

Select an option

Save fabioluz/f7f89f35b62acb5b4f05ffe59be1880e to your computer and use it in GitHub Desktop.
<template>
<!--<require from="./optional-title"></require>-->
${message}
<br>
<select>
<option repeat.for="option of options" my-optional-title.bind="option.title">
${option.name}
</option>
</select>
</template>
import { customAttribute } from 'aurelia-framework';
export class App {
message = 'Hello World!';
options = [
{ name: '1' },
{ name: '2', title: 'adf' },
{ name: '3', title: 'aaa' }
];
}
@customAttribute('my-optional-title')
export class SomeClassName {
static inject = [Element];
constructor(element) {
this.element = element;
}
valueChanged(newValue) {
if (newValue) {
this.element.setAttribute('title', newValue);
} else {
this.element.removeAttribute('title');
}
}
}
<!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>
export class OptionalTitleCustomAttribute {
static inject = [Element];
constructor(element) {
this.element = element;
}
valueChanged(newValue) {
if (newValue) {
this.element.setAttribute('title', newValue);
} else {
this.element.removeAttribute('title');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment