Skip to content

Instantly share code, notes, and snippets.

@valichek
Last active March 1, 2017 22:06
Show Gist options
  • Save valichek/e1243ac2bfad79c7f6ee2dd6b1b68c1f to your computer and use it in GitHub Desktop.
Save valichek/e1243ac2bfad79c7f6ee2dd6b1b68c1f 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()" 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() {
console.log("removeItem");
this.remove({item: this.item, someParam: "Called from ListItem VM"})
}
}
<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, someParam)"></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, someParam){
var index = this.listitems.indexOf(item);
if (index>-1){
this.listitems.splice(index,1)
}
console.log('delete ' + index, someParam)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment