Skip to content

Instantly share code, notes, and snippets.

@jasoncarreira
Last active May 15, 2017 15:43
Show Gist options
  • Save jasoncarreira/d1efe36d54a58f291eff09bbd467f8dd to your computer and use it in GitHub Desktop.
Save jasoncarreira/d1efe36d54a58f291eff09bbd467f8dd to your computer and use it in GitHub Desktop.
Custom element value binding
<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>
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);
}
}
<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>
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';
}
<!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>
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());
}
/* todo: add styles */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment