Last active
May 15, 2017 15:43
-
-
Save jasoncarreira/d1efe36d54a58f291eff09bbd467f8dd to your computer and use it in GitHub Desktop.
Custom element value binding
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> | |
<require from="./au-input"></require> | |
<au-input value.bind="value" type="number" prefix.bind="prefix" suffix.bind="suffix" label.bind="label" view-model.ref="inputModel"></au-input> | |
<au-input value.bind="value" type="number" prefix="$$"></au-input> | |
</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
export class App { | |
percent= false; | |
prefix = "$"; | |
suffix; | |
label = "Dollar value"; | |
value = 10; | |
inputModel; | |
onClick() { | |
// console.log('clicked: percent = ' + this.percent + ' inputModel = ' + this.inputModel); | |
this.percent = !this.percent; | |
this.prefix = this.percent ? null : "$"; | |
this.suffix = this.percent ? "%" : null; | |
this.label = this.percent ? "Percentage value" : "Dollar value"; | |
// console.log('clicked: percent = ' + this.percent + ' inputModel = ' + this.inputModel); | |
} | |
valueChange(newValue, oldValue) { | |
// console.log('value changed from ' + oldValue + ' ' + newValue); | |
} | |
} |
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> | |
<h1>${label} - ${value}</h1> | |
<div class="input-group"> | |
<span if.bind="prefix" class="input-group-addon">${prefix}</span> | |
<input type="${type}" class="form-control" aria-label="${label}" value.bind="value"> | |
<span if.bind="suffix" class="input-group-addon">${suffix}</span> | |
</div> | |
</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 {bindable,bindingMode} from 'aurelia-framework'; | |
export class AuInput { | |
@bindable({defaultBindingMode: bindingMode.twoWay}) value; | |
@bindable label : string; | |
@bindable prefix : string; | |
@bindable suffix : string; | |
@bindable type: string = 'text'; | |
} |
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"> | |
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> | |
</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
import {Aurelia} from "aurelia-framework"; | |
import environment from "./environment"; | |
import {UIConfig} from "aurelia-ui-framework"; | |
export function configure(aurelia: Aurelia) { | |
aurelia.use | |
.standardConfiguration(); | |
aurelia.start().then(() => aurelia.setRoot()); | |
} |
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
/* todo: add styles */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment