Skip to content

Instantly share code, notes, and snippets.

@TylerJPresley
Last active March 7, 2017 19:43
Show Gist options
  • Save TylerJPresley/dd4309c714e2f06b5cf4a907f26f0c41 to your computer and use it in GitHub Desktop.
Save TylerJPresley/dd4309c714e2f06b5cf4a907f26f0c41 to your computer and use it in GitHub Desktop.
DI inheritance
<template>
<require from="type-ahead-filter-value-converter"></require>
<input type="text" value.bind="_filter">
<hr>
<div repeat.for="item of items | typeAheadFilter:'text':_filter">${item.text}</div>
</template>
export class App {
items = [
{ id: 1, text: 'apple' },
{ id: 2, text: 'peach' },
{ id: 3, text: 'orange' },
{ id: 4, text: 'berry' },
{ id: 5, text: 'melon' }
];
}
<!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>
export class TypeAheadFilterValueConverter {
toView(value, prop, filterText) {
if (!Array.isArray(value) || !filterText) {
return value;
}
return value.filter((i) => i[prop].indexOf(filterText) > -1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment