fast-bind icon indicating copy to clipboard operation
fast-bind copied to clipboard

Fixed broken binding once for attributes.

Open kersh opened this issue 10 years ago • 2 comments

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.

kersh avatar Mar 10 '14 10:03 kersh

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?

kseamon avatar Mar 13 '14 11:03 kseamon

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.

kasperlewau avatar Mar 13 '14 13:03 kasperlewau