Last active
August 8, 2016 21:25
-
-
Save ccamarat/cff63f58ce461972f1beee08327d0230 to your computer and use it in GitHub Desktop.
Aurelia "repeat.for" in child components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<require from="./table-head-normal.html"></require> | |
<require from="./table-head-aurelia.html"></require> | |
This is the "normal" way of looping. Note that it doesn't work in Aurelia: | |
<table> | |
<thead as-element="table-head-normal" headings.bind="headings"></thead> | |
</table> | |
<hr /> | |
It will work if you elect to not DRY up your code, but this isn't really desirable: | |
<table> | |
<thead> | |
<tr> | |
<th repeat.for="heading of headings">${heading}</th> | |
</tr> | |
</thead> | |
</table> | |
<hr /> | |
So, what you need to do is wrap your TH in a `template` and put the looping directive on it instead: | |
<table> | |
<thead as-element="table-head-aurelia" headings.bind="headings"></thead> | |
</table> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class App { | |
constructor () { | |
this.headings = ['Id', 'Stain', 'Comment', 'Status', 'Date Created']; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template bindable="headings"> | |
<require from="table-head.css"></require> | |
<tr> | |
<template repeat.for="heading of headings"> | |
<th>${heading}</th> | |
</template> | |
</tr> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template bindable="headings"> | |
<require from="table-head.css"></require> | |
<tr> | |
<th repeat.for="heading of headings">${heading}</th> | |
</tr> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Obviously this would be scoped better */ | |
th { | |
font-style: italic; | |
padding: 10px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment