Created
November 7, 2016 20:58
-
-
Save AStoker/58a2fa113ddf480ef3b426e8e2918975 to your computer and use it in GitHub Desktop.
Aurelia "with" and "ref" https://github.com/aurelia/templating/issues/376
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="./pagerCustomElement"></require> | |
<pager items.bind="tracks"> | |
<div slot="title-template">Some song</div> | |
<div slot="content-template"> | |
<div repeat.for="line of item.content"> | |
Line: ${$index + 1}. ${line.lyric} | |
</div> | |
</div> | |
</pager> | |
</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 { | |
tracks = [ | |
{ title: 'Walking on the Sun', content: [ | |
{ | |
lyric:'foo' | |
}, | |
{ | |
lyric:'bar' | |
} | |
] | |
}, | |
{ title: 'All Star', content: [ | |
{ | |
lyric:'boo' | |
}, | |
{ | |
lyric:'blah' | |
} | |
] | |
} | |
] | |
} |
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> | |
<div repeat.for="item of selectedItems"> | |
<slot name="title-template"> | |
<div>${item.title}</div> | |
</slot> | |
<slot name="content-template"> | |
<div repeat.for="line of item.content"> | |
${$index + 1}. ${line.lyric} | |
</div> | |
</slot> | |
</div> | |
</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
import { bindable, computedFrom } from 'aurelia-framework'; | |
export class PagerCustomElement { | |
@bindable pageSize = 10; | |
@bindable items; | |
currentPage = 0; | |
@computedFrom('currentPage') | |
get selectedItems() { | |
let pageSize = this.pageSize; | |
let currentPage = this.currentPage; | |
return this.items.slice(pageSize * currentPage, pageSize); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment