Last active
July 8, 2019 18:31
-
-
Save kabaehr/a556aec0c3c4aee1545b80ed9ffc7d3e to your computer and use it in GitHub Desktop.
Aurelia .call examples
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
ul { | |
height: 100px; | |
background-color: aliceblue; | |
overflow-y: scroll; | |
} |
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="button-component"></require> | |
<require from="checkbox-component"></require> | |
<require from="scroll-end"></require> | |
<require from="app.css"></require> | |
<h2>.Call Examples</h2> | |
<h3> .call example custom element</h3> | |
<checkbox-component callback.call="checkboxToggle()" labels.bind="{ true : 'checked', false: 'not checked'}"></checkbox-component> | |
<hr> | |
<h3>.call example with a custom attribute for loading more items in a list</h3> | |
<ul scroll-end="load.call:loadItems()" class="list"> | |
<li repeat.for="item of items"> | |
${item} | |
</li> | |
</ul> | |
<hr> | |
<h3>.call example for callback functions</h3> | |
<button-component callback.call="buttonInAppClicked()">Click me!</button-component> | |
</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 { | |
items = [1, 2, 3, 4, 5, 6, 7, 8, 9]; | |
buttonInAppClicked() { | |
alert("button callback called"); | |
} | |
loadItems() { | |
//here you could do a REST call e.g. | |
for(var i = 1; i <= 5; i++) | |
this.items.push('new item ' + i); | |
} | |
checkboxToggle() { | |
alert("checkbox toggle called"); | |
} | |
} |
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> | |
<input type="checkbox" checked.bind="checkValue" change.delegate="callback()"> ${labels[checkValue]} | |
</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 } from 'aurelia-framework'; | |
export class CheckboxComponentCustomElement { | |
@bindable callback; | |
@bindable labels; | |
checkValue = false; //default state | |
} |
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://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> |
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 , inject } from 'aurelia-framework'; | |
@inject(Element) | |
export class ScrollEndCustomAttribute { | |
@bindable load; | |
element; | |
constructor(element) { | |
this.element = element; | |
} | |
attached() { | |
this.element.addEventListener('scroll', () => { | |
if (this.element.scrollTop + this.element.offsetHeight >= this.element.scrollHeight) { | |
this.load(); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment