-
-
Save arjanvanderleden/81fe027a6bf0719e08a91df5e5900fe2 to your computer and use it in GitHub Desktop.
Double binding
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> | |
<select value.bind="currentLanguage"> | |
<option repeat.for="language of languages" value.bind="language">${language}</option> | |
</select> (${currentLanguage}) | |
<item-view repeat.for="item of items" item.bind="item" language.bind="currentLanguage" click.delegate="setCurrentItem(item)"></item-view> | |
<hr/> | |
<item-view if.bind="currentItem" item.bind="currentItem" language.two-way="currentLanguage"></item-view> | |
</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 {inject} from 'aurelia-dependency-injection'; | |
import {bindable} from 'aurelia-binding'; | |
import {Item} from './item'; | |
export class App { | |
items=[ | |
new Item(1,'one'), | |
new Item(2,'two'), | |
new Item(3,'three'), | |
new Item(4,'four') | |
] | |
languages = ['nl','en']; | |
currentLanguage; | |
currentItem: Item; | |
constructor(){ | |
this.currentLanguage = this.languages[1]; | |
} | |
setCurrentItem(item){ | |
this.currentItem = item; | |
} | |
} | |
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="main" class="container"> | |
<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/babel.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.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> | |
<span>${item.number}</span> | |
<span>${item.label} (${language})</span> | |
</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 {inject} from 'aurelia-dependency-injection'; | |
import {bindable} from 'aurelia-framework'; | |
export class ItemView { | |
@bindable item : Object; | |
@bindable language : string; | |
constructor(){ | |
console.log('constructor') | |
} | |
bind(x,y){ | |
console.log('bind'); | |
} | |
attached = function(){ | |
console.log('attached'); | |
} | |
languageChanged(){ | |
console.log('languageChanged') | |
} | |
itemChanged = function(){ | |
console.log('itemChanged') | |
} | |
} |
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 Item { | |
number : number; | |
label : string; | |
constructor(number : number, label:string){ | |
this.number = number; | |
this.label = label; | |
} | |
} |
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 function configure(aurelia) { | |
aurelia.use.standardConfiguration() | |
.developmentLogging() | |
.globalResources(['./item-view']) | |
aurelia.start().then(() => aurelia.setRoot()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment