Skip to content

Instantly share code, notes, and snippets.

@Reverbe
Forked from arjanvanderleden/app.html
Created January 6, 2017 14:57
Show Gist options
  • Save Reverbe/1d64bc04410803f08ba7175c772bb44b to your computer and use it in GitHub Desktop.
Save Reverbe/1d64bc04410803f08ba7175c772bb44b to your computer and use it in GitHub Desktop.
Aurelia Skeleton list list-item implementation
<template>
<require from="./list"></require>
<div>List</div>
<list></list>
</template>
export class App {
message = 'hello world';
attached(){
console.log('app = attached');
}
}
<!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://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>
<template>
<div>
<span>${item.name}</span>
<i click.delegate="removeItem(item)" class="icon trash" style="cursor:pointer"> - </i>
</div>
</template>
import {inject,bindable, customElement} from 'aurelia-framework';
@customElement("list-item")
export class ListItem {
@bindable remove;
@bindable item;
removeItem(item) {
console.log(this, 'child action');
this.remove()
}
}
<template>
<require from="./list-item"></require>
<div class="list">
<div class="new-item">
<input value.bind="newListItemName" placeholder="New item name"/> <span click.delegate="newItem()" style="cursor:pointer">+</span>
</div>
<list-item repeat.for="item of listitems" item.bind="item" remove.call="deleteItem(item)"></list-item>
</div>
</template>
import {inject,bindable, customElement} from 'aurelia-framework';
import {ListItem} from 'list-item';
@customElement("list")
export class List{
listitems = [];
@bindable newListItemName;
newItem(){
console.log('new item: ' + this.newListItemName);
if (this.newListItemName){
this.listitems.push({name:this.newListItemName});
}
}
deleteItem(item){
console.log(this, 'parent action');
var index = this.listitems.indexOf(item);
if (index>-1){
this.listitems.splice(index,1)
}
console.log('delete ' + index)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment