Skip to content

Instantly share code, notes, and snippets.

@jsobell
Created November 14, 2017 09:10
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 jsobell/03c20c3eb2ffe374b2db4bc12c1d1679 to your computer and use it in GitHub Desktop.
Save jsobell/03c20c3eb2ffe374b2db4bc12c1d1679 to your computer and use it in GitHub Desktop.
Aurelia Gist
<template>
<p>Hit edit and you'll see two items added to the form instead of one.</p>
<div if.bind="!editing">
<h2>${items.length} items!</h2>
<ul>
<li repeat.for="item of items">
${item.name}
</li>
</ul>
<button click.delegate="toggleEditing()">Edit</button>
</div>
<div if.bind="editing">
<ul>
<li repeat.for="item of items">
<input type="text" value.bind="item.name">
</li>
</ul>
<button click.delegate="toggleEditing()">Save</button>
</div>
</template>
export class App {
constructor () {
this.items = [];
this.editing = false;
}
// Toggle the edit form
toggleEditing () {
this.editing = !this.editing;
// Also add a new item
setTimeout(a => {
if (this.editing) {
this.items.push({}); // NOTE: This is where things go wrong
}
},0);
}
}
<!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