Skip to content

Instantly share code, notes, and snippets.

@floydpink
Forked from jdanyow/app.html
Created July 11, 2016 22:43
Show Gist options
  • Save floydpink/21991c490810a4acf2e38cec99614bbd to your computer and use it in GitHub Desktop.
Save floydpink/21991c490810a4acf2e38cec99614bbd to your computer and use it in GitHub Desktop.
How to conditionally display client-side data with Aurelia
<template>
<ul>
<li repeat.for="obj of data" if.bind="obj.customDataType">
<span>${obj.customDataType.cdt}</span> -
<strong repeat.for="cda of obj.customDataArray">${cda}, </strong>
</li>
<li repeat.for="obj of data" if.bind="!obj.customDataType">
<span>No CustomDataType</span> -
<strong repeat.for="cda of obj.customDataArray">${cda}, </strong>
</li>
</ul>
</template>
export class App {
data = [{
objectID: 1,
customDataArray: [1, 2, 3, 4],
customDataType: {
cdt: "Troops"
}
},{
objectID: 2,
customDataArray: [11, 22, 33, 44],
customDataType: {
cdt: "Artilleries"
}
},{
objectID: 3,
customDataArray: [21, 32, 43, 54]
}];
}
<!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