-
-
Save fabioluz/827c72ec2062ec61adbfb0a72b4dac7d to your computer and use it in GitHub Desktop.
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> | |
<require from="./dynamic-element"></require> | |
<div> | |
Text Box | |
<text-box value.bind="text"></text-box> | |
</div> | |
<div> | |
Date Picker | |
<date-picker value.bind="date"></date-picker> | |
</div> | |
<div> | |
Dynamic controls: | |
<div repeat.for="control of controls"> | |
${control.label} | |
<dynamic-element type.bind="control.type" model.bind="control.value"></dynamic-element> | |
<div> | |
control.value = ${control.value} | |
</div> | |
</div> | |
</div> | |
<button click.trigger="changeModelOnTextBox()">Change model on text box</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
export class App { | |
text = 'This is some text'; | |
date = '2017-02-28'; | |
controls = [ | |
{label: 'Entry Date', type: 'date-picker', value: '2017-01-01' }, | |
{label: 'Code', type: 'text-box', value: 'This is some other text'} | |
]; | |
changeModelOnTextBox() { | |
this.controls[1].value = 'I changed the model!'; | |
} | |
} |
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> | |
<input type="date" value.bind="value" /> | |
</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, bindable, bindingMode, TaskQueue } from 'aurelia-framework'; | |
@inject(Element, TaskQueue) | |
export class DatePicker { | |
@bindable({ defaultBindingMode: bindingMode.twoWay }) value; | |
model = null; | |
constructor(el, taskQueue) { | |
this.el = el; | |
this.taskQueue = taskQueue; | |
} | |
activate(model) { | |
this.guard = true; | |
this.value = model.value; | |
this.model = model; | |
this.hasModel = true; | |
this.taskQueue.queueMicroTask(() => this.guard = false) | |
} | |
valueChanged() { | |
if(this.guard == false && this.hasModel) { | |
this.model.value = this.value; | |
} | |
} | |
} |
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 { | |
bindable, | |
inlineView, | |
noView, | |
inject, | |
TemplatingEngine, | |
bindingMode | |
} from 'aurelia-framework'; | |
@noView | |
@inject(Element, TemplatingEngine) | |
export class DynamicElement { | |
@bindable type; | |
@bindable({ defaultBindingMode: bindingMode.twoWay }) model; | |
constructor(element, templatingEngine) { | |
this.element = element; | |
this.templatingEngine = templatingEngine; | |
} | |
bind(bindingContext, overrideContext) { | |
this.element.innerHTML = `<${this.type} value.bind="model"></${this.type}>`; | |
this.view = this.templatingEngine.enhance({ element: this.element, bindingContext: this }); | |
} | |
detached() { | |
this.element.firstChild.remove(); | |
this.view.detached(); | |
this.view.unbind(); | |
this.view = null; | |
} | |
} |
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"> | |
<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 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([ | |
'./date-picker', | |
'./text-box' | |
]); | |
aurelia.start().then(a => a.setRoot()); | |
} |
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> | |
<input type="text" value.bind="value" /> | |
</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, bindable, bindingMode, TaskQueue } from 'aurelia-framework'; | |
@inject(Element, TaskQueue) | |
export class TextBox { | |
@bindable({ defaultBindingMode: bindingMode.twoWay }) value; | |
// model = null; | |
constructor(el, taskQueue) { | |
this.el = el; | |
this.taskQueue = taskQueue; | |
} | |
// activate(model) { | |
// this.guard = true; | |
// this.value = model.value; | |
// this.model = model; | |
// this.hasModel = true; | |
// this.taskQueue.queueMicroTask(() => this.guard = false) | |
// } | |
valueChanged() { | |
// if(this.guard == false && this.hasModel) { | |
// this.model.value = this.value; | |
// } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment