Created
November 25, 2016 09:54
-
-
Save Yiin/2a4b877feed1d3c9305965946e7fc11a 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
<button dynamic="attrs.bind: attrs">Button</button> | |
<!-- Generated HTML: <button name="foo" type="bar" dynamic="attrs.bind: attrs">Button</button> --> |
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
... | |
this.attrs = JSON.stringify({ | |
name: 'foo', | |
type: 'bar' | |
}); |
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 {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