Skip to content

Instantly share code, notes, and snippets.

@jdanyow
Last active June 13, 2016 13:45
Show Gist options
  • Save jdanyow/7d4355903dcafaa476d2 to your computer and use it in GitHub Desktop.
Save jdanyow/7d4355903dcafaa476d2 to your computer and use it in GitHub Desktop.

main.js:

export function configure(aurelia) {
  aurelia.use
    .standardConfiguration()
    .developmentLogging();

  // Assuming a file named "knockout-custom-attribute.js", containing the
  // custom attribute class defined above, exists in the root of the project:
  aurelia.use.globalResources('./knockout-custom-attribute');

  aurelia.start().then(a => a.setRoot());
}

usage:

<!-- apply the "knockout" attribute to sections of html containing knockout bindings -->
<div knockout>
  <input data-bind="value: firstName">
  <input data-bind="value: lastName">
</div>
import ko from 'ko';
export class KnockoutCustomAttribute {
static inject = [Element];
constructor(element) {
this.element = element;
}
bind(bindingContext) {
ko.applyBindings(bindingContext, this.element)
}
unbind() {
ko.cleanNode(this.element);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment