Skip to content

Instantly share code, notes, and snippets.

@AshleyGrant
Forked from andrewflierman/app.html
Created July 20, 2016 15:24
Show Gist options
  • Save AshleyGrant/4e214dec2a81e47b45904d745bf5a4ee to your computer and use it in GitHub Desktop.
Save AshleyGrant/4e214dec2a81e47b45904d745bf5a4ee to your computer and use it in GitHub Desktop.
Aurelia RequireJS Gist
<template>
<require from="./autocomplete"></require>
<div>Type something in the input and the message should change into 'calculatedPrice()!'</div>
<h1>${message}</h1>
<autocomplete selected.delegate="calculatePrice()"></autocomplete>
</template>
export class App {
message = 'Hello World!';
calculatePrice(){
this.message = "calculatedPrice!"
}
}
<template>
<div>
<input type="text" autocomplete="off" value.bind="value & debounce">
</div>
</template>
import {inject, bindable, customElement} from "aurelia-framework";
@customElement("autocomplete")
@inject(Element)
export class Autocomplete {
@bindable value = "";
constructor(element, autocompleteService) {
this.element = element;
}
valueChanged(newValue) {
let selectEvent;
if (window.CustomEvent) {
selectEvent = new CustomEvent("selected", { bubbles: true });
} else {
selectEvent = document.createEvent("CustomEvent");
selectEvent.initCustomEvent("selected", true, true, {});
}
console.log('firing event');
this.element.dispatchEvent(selectEvent);
}
}
<!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