fast-bind
fast-bind copied to clipboard
Fixed broken binding once for attributes.
Previous version didn't work with {{}} expressions and didn't work correctly with latest Angular version. This version:
- Binds attributes correctly.
- Works with {{}} markup.
If I have more spare time on work, I will write tests for this directive.
Sorry for the delay.
I'm not sure that this is desirable in all cases.
With your approach, we pay a performance penalty (Moving work from compile to link and indirectly introducing the interpolate directive into the element) so that this would work:
fast-bind-attr-once="{href: '{{obj.url}}', title: '{{obj.urlTitle}}'}"
But before, I'm pretty sure that this would have worked:
fast-bind-attr-once="{href: obj.url, title: obj.urlTitle}"
(Though the example in the comments was wrong about how to do this).
Thoughts?
ScopeData: $scope.user = { username: 'kasperlewau' };
Attaching fast-bind-attr-once="{username: user.username}
to an element with a simple console.log($attrs);
directive yields this:
"username: username"
Switching around key & value in attributes.$set(key, value);
into attributes.$set(value, key);
yields:
"kasperlewau: kasperlewau"
Switching out attributes
for attrs
in the link step of fast-bind-attr-once, appears to solve this.
Not sure if this is the intended behaviour of fast-bind-attr-once, as I haven't used it much personally. I have however had great success with fast-binding attributes to the actual DOM element through the usage of element[0][key] = value
in place of the attributes.$set()
method.
I suppose I could follow up with; What is the intended usage of fast-bind-attr-once? Is it indeed to expose attributes for other directives to hook into, or is there some other case that I'm missing?
Cheers.