Skip to content

Instantly share code, notes, and snippets.

@Yiin
Created November 25, 2016 09:54
Show Gist options
  • Save Yiin/2a4b877feed1d3c9305965946e7fc11a to your computer and use it in GitHub Desktop.
Save Yiin/2a4b877feed1d3c9305965946e7fc11a to your computer and use it in GitHub Desktop.
<button dynamic="attrs.bind: attrs">Button</button>
<!-- Generated HTML: <button name="foo" type="bar" dynamic="attrs.bind: attrs">Button</button> -->
...
this.attrs = JSON.stringify({
name: 'foo',
type: 'bar'
});
import {dynamicOptions, autoinject} from 'aurelia-framework';
@dynamicOptions
@autoinject
export class DynamicCustomAttribute {
constructor(private element: Element) {
}
propertyChanged(name: string, value) {
if (name === 'attrs') {
let attrs = JSON.parse(value);
for (let key in attrs) {
this.element.setAttribute(key, attrs[key]);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment