From Directives documentation it says to inherit scope in this two ways:
@ or @attr - bind a local scope property to the value of DOM attribute. The result is always a string since DOM attributes are strings. If no attr name is specified then the attribute name is assumed to be the same as the local name. Given and widget definition of scope: { localName:'@myAttr' }, then widget scope property localName will reflect the interpolated value of hello {{name}}. As the name attribute changes so will the localName property on the widget scope. The name is read from the parent scope (not component scope).
= or =attr - set up bi-directional binding between a local scope property and the parent scope property of name defined via the value of the attr attribute. If no attr name is specified then the attribute name is assumed to be the same as the local name. Given and widget definition of scope: { localModel:'=myAttr' }, then widget scope property localModel will reflect the value of parentModel on the parent scope. Any changes to parentModel will be reflected in localModel and any changes in localModel will reflect in parentModel.
Considering that i want to pass elementId, which is just an id, I can pass it through =elementId or @elementId.
Now which one of the two is considered best practice? If I use the @
and therefore the attribute, it will take the value from the DOM which is slower than taking directly the value?
Am I correct? Any suggestions?
For your case, @ seems best. (An example of how you would use the directive and elementID in an HTML element would be helpful though.)
I have no idea which is slower/faster.
See also What is the difference between '@' and '=' in directive scope in AngularJS?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With