-
-
Save atsu85/a0b464fac33af860d435a37fbb3b410d to your computer and use it in GitHub Desktop.
binding two values (test)
This file contains hidden or 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> | |
validator.value <input type="text" value.bind="validator.violatedConstraints"> | |
</div> | |
<div> | |
bar.value <input type="text" value.bind="bar.value"> | |
</div> | |
<hr/> | |
<p>validator.violatedConstraints 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 hidden or 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 {Validator} from './Validator' | |
import {Bar} from './bar' | |
@inject(BindingEngine) | |
export class App { | |
validator = new Validator(); | |
bar = new Bar(); | |
constructor(bindingEngine){ | |
this.bindingEngine = bindingEngine; | |
console.log() | |
} | |
stop( ){ | |
this.binding.unbind(); | |
this.binding = undefined; | |
} | |
start(){ | |
let expression = this.bindingEngine.createBindingExpression('value', 'violatedConstraints', bindingMode.twoWay); | |
this.binding = expression.createBinding(this.bar); | |
// let scope = {validator: this.validator, bindingContext: this.validator}; | |
let scope = {bindingContext: this.validator}; | |
this.binding.bind(scope); | |
} | |
} |
This file contains hidden or 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 hidden or 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 hidden or 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 Validator{ | |
constructor(){ | |
this.violatedConstraints = 10; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment