-
Notifications
You must be signed in to change notification settings - Fork 27.5k
feat($compile): Allow late binding attributes #2061
Conversation
The PR updates documentation and include relevant tests. I've already signed the CLA. |
You can see a live-demo of the feature here: http://plnkr.co/edit/7GDN3qybyLIMsANvBIC9?p=preview |
late prefix doesn't make it clear that this is an Angular core directive. ngAttr*? |
@IgorMinar, fixed. Now it allows multiple prefixes: ng-attr-, ng:attr:, ng_attr_*, etc. |
few minor implementation changes requested otherwise I like this PR a lot.
PR Checklist (Minor Feature)
|
Sometimes is not desirable to use interpolation on attributes because the user agent parses them before the interpolation takes place. I.e: <svg> <circle cx="{{cx}}" cy="{{cy}}" r="{{r}}"></circle> </svg> The snippet throws three browser errors, one for each attribute. For some attributes, AngularJS fixes that behaviour introducing special directives like ng-href or ng-src. This commit is a more general solution that allows prefixing any attribute with "ng-attr-", "ng:attr:" or "ng_attr_" so it will be set only when the binding is done. The prefix is then removed. I.e: <svg> <circle ng_attr_cx="{{cx}}" ng-attr-cy="{{cy}}" ng:Attr:r="{{r}}"></circle> </svg> Closes angular#1050 Closes angular#1925
Done! I hope everything is ok now. |
for some reason this change seems to cause timeouts on our CI server.. investigating... |
landed as dc2fd96beec6700943e2bb2e0ed624decfb3a403 thanks! |
@lrlopez, the plunker link you have specified ( http://plnkr.co/edit/7GDN3qybyLIMsANvBIC9?p=preview ) does not render circle. I have tried this with rect also but nothing is rendered in the browser. console errors are gone. <svg>
<rect ng-attr-x="{{rec_.x}}" ng-attr-y="{{rec_.y}}" width="100" height="100" />
</svg> but following does NOT work: (nothing rendered): <svg>
<rect ng-attr-x="{{rec_.x}}" ng-attr-y="{{rec_.y}}" ng-attr-width="{{rec_.width}}" ng-attr-height="{{rec_.height}}" /></svg> |
@lrlopez, In my previous post, I mentioned that circle is not rendered when used within angular to define attributes either by using ng-attr/ x-ng-attr/ ng:attr. When I debugged the generated circle element, I realized that the attribute names are InitCap and that seems the issue. <circle x-ng-attr-cx="{{cx}}" ng-attr-cy="{{cy}}" ng:attr:r="{{r}}" Cx="100" Cy="100" R="40"></circle> The same issue is with rect attributes. I hope, this findings will help. |
@dparikh The library used on the Plunker is based on an old version of the patch. I will try to update the link tomorrow, thanks for pointing it out |
@lrlopez Thanks. I saw the modified compile.js you have commited and tried the changes locally, which is working fine now. Below is the content from console in Chrome: <rect x-ng-attr-width="{{content.width}}"
ng-attr-height="{{content.height}}"
x-ng-attr-x="{{content.x}}"
x-ng-attr-y="{{content.y}}"
width height x y>
</rect> Any thoughts/pointers would be helpful. Thanks |
Hmmm... it sounds like 'content' is not on the scope. Can you show me a Plunker so I can have a look into the issue? |
@lrlopez Ok. I will create a plunker to reproduce my error and let you know. |
@lrlopez, I got it working as I wanted to at: http://plnkr.co/edit/yCh1Z7wbQKLY2BmQjnoU?p=preview Thanks for your help.. |
Good to know it's solved... |
Sometimes is not desirable to use interpolation on attributes because the user agent parses them before the interpolation takes place. I.e:
The snippet throws three browser errors, one for each attribute.
For some attributes, AngularJS fixes that behaviour introducing special directives like ng-href or ng-src.
This commit is a more general solution that allows prefixing any attribute with "ng-attr-", "ng:attr:" or "ng_attr_" so it will be set only when the binding is done. The prefix is then removed.
I.e:
Closes #1050
Closes #1925