Skip to content

Instantly share code, notes, and snippets.

@specimen151
Forked from jdanyow/app.html
Last active May 12, 2017 13:51
Show Gist options
  • Save specimen151/dd11c5837b77b29b586d2c4f978a7a48 to your computer and use it in GitHub Desktop.
Save specimen151/dd11c5837b77b29b586d2c4f978a7a48 to your computer and use it in GitHub Desktop.
Aurelia Gist
<template>
<require from="./comma-list"></require>
Topics:
<input type="text" value.bind="contact.topics|commaList"></input>
<br />Use the button, or append textually above
<p>
Repeat.for contact's topics:
<ul>
<li repeat.for="topic of contact.topics">${topic}</li>
</ul>
</p>
Length of list: ${contact.topics.length}
<br/>(but observe console for a printout of list, which is +1 element)
<hr />
<!-- the rest is just to compare with regular list/list-inside-obj -->
<p>
Repeat.for a separate list (not inside an object):
<div repeat.for="f of fruit">Fruit: ${f}
</div>
</p>
<p>
Repeat.for separate list inside an object:
<div repeat.for="f of obj.fruit">Fruit: ${f}
</div>
</p>
<p>
Update:
<button click.delegate="addRandomTopic()">Add topic</button>
</p>
</template>
export class App {
obj = {}
attached() {
this.contact = {name:"John",topics:['food','wine']}
this.obj.fruit = ['banana','apple','mango']
this.fruit = ['banana','apple','mango']
}
addRandomTopic() {
this.contact.topics.push('fotball')
this.obj.fruit.push('pear')
this.fruit.push('pear')
console.log(this.contact.topics)
}
}
export class CommaListValueConverter {
toView(value) {
if(!value) return value
return value.join('|')
}
fromView(value) {
if(!value) return value
return value.split('|')
}
}
<!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