Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed broken binding once for attributes. #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kersh
Copy link

@kersh kersh commented Mar 10, 2014

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.

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.
@kseamon
Copy link
Owner

kseamon commented Mar 13, 2014

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?

@kasperlewau
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants