Skip to content

Instantly share code, notes, and snippets.

@Alexander-Taran
Forked from putstrln/app.html
Last active April 8, 2018 20:53
Show Gist options
  • Save Alexander-Taran/e04b44bf6fd5c53668517fb9c5faaa04 to your computer and use it in GitHub Desktop.
Save Alexander-Taran/e04b44bf6fd5c53668517fb9c5faaa04 to your computer and use it in GitHub Desktop.
Template binding for array
<template>
<h1>Referencing other fields in repeat.for of another field</h1>
<p>Even though randoms is updated, times repeat isn't re-rendered since randoms isn't watched in that loop.</p>
<p>To re-render the times loop, we need to use a signal to refresh the UI.</p>
<h2>Times</h2>
<ul>
<li repeat.for='time of times'>
# ${$index} Time - ${time} <-> Random - ${randoms[$index] }
</li>
</ul>
<h2>Randoms</h2>
<ul>
<li repeat.for='random of randoms'>
${random}
</li>
</ul>
</template>
export class App {
times = [1, 2, 3]
randoms = [0, 14831431, 0]
attached() {
setInterval(() => {
this.times.splice(1, 1, Date.now())
let newRandoms = this.randoms.slice()
newRandoms.splice(1, 1, Math.random())
this.randoms = newRandoms
}, 1000)
}
getRandom(index) {
return this.randoms[index]
}
}
<!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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment