Last active
September 7, 2016 08:49
-
-
Save sylvain-hamel/9fae8e13e9d5e4526ab498504d9bcd51 to your computer and use it in GitHub Desktop.
binding two values
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> | |
foo.value <input type="text" value.bind="foo.value"> | |
</div> | |
<div> | |
bar.value <input type="text" value.bind="bar.value"> | |
</div> | |
<hr/> | |
<p>foo.value is the source, bar.value is the target</p> | |
<button click.trigger="start()">Start sync</button> | |
<button click.trigger="stop()">Stop sync</button> | |
</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 {BindingEngine, bindingMode} from 'aurelia-binding'; | |
import {inject} from 'aurelia-framework'; | |
import {Foo} from './foo' | |
import {Bar} from './bar' | |
@inject(BindingEngine) | |
export class App { | |
foo = new Foo(); | |
bar = new Bar(); | |
constructor(bindingEngine){ | |
this.bindingEngine = bindingEngine; | |
console.log() | |
} | |
stop( ){ | |
this.binding.unbind(); | |
this.binding = undefined; | |
} | |
start(){ | |
let expression = this.bindingEngine.createBindingExpression('value', 'value', bindingMode.twoWay); | |
this.binding = expression.createBinding(this.bar); | |
let scope = {foo: this.foo, bindingContext: this.foo}; | |
this.binding.bind(scope); | |
} | |
} |
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 Bar{ | |
constructor(){ | |
this.value = 50; | |
} | |
} |
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 Foo{ | |
constructor(){ | |
this.value = 10; | |
} | |
} |
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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment