Skip to content

Instantly share code, notes, and snippets.

@jdanyow
Forked from 3cp/app.html
Created September 23, 2016 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdanyow/052bbfdb6bdc260d030d44ee07aa4f72 to your computer and use it in GitHub Desktop.
Save jdanyow/052bbfdb6bdc260d030d44ee07aa4f72 to your computer and use it in GitHub Desktop.
aurelia-test
<template>
<require from="./child"></require>
<button click.delegate="newItems()">new items</button>
<child repeat.for="item of items" id.bind="item.id" value.bind="item.value"></child>
</template>
export class App {
items = []
newItems() {
if (this.items.length === 0) {
this.items.push({id: 'A', value: 1});
} else {
const oldItem = this.items[0];
this.items = [{id: 'new', value: 'new'}];
oldItem.value = 2;
}
}
}
<template>
<div style="border: 1px solid gray">
<p>id:${id}, value: ${value}</p>
</div>
</template>
import {bindable} from 'aurelia-framework';
export class Child {
@bindable id = '';
@bindable value = 0;
bind() {
$('body').append(`<p>id:${this.id} bind</p>`);
}
valueChanged(newValue, oldValue) {
$('body').append(`<p>id:${this.id} value changed to ${newValue}</p>`);
}
unbind() {
$('body').append(`<p>id:${this.id} unbind</p>`);
}
}
<!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://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
<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