1

Just wanted some clarifications. I was told that you are suppose to use ngAttr when there are interpolated markup. For example:

<div ng-attr-name={{Name}}></div>

I also seen some codes online where there are interpolated markups but they do not use ngAttr. Are there certain situations when you use ngAttr and not use ngAttr when dealing with interpolated markups?

Ron T
  • 397
  • 1
  • 4
  • 22

1 Answers1

1

I recall running into this issue when working with <svg/> and attempting to interpolate attributes such as cx (which happens to be the classic example in the current angularjs documentation). The browser will complain when you attempt the following:

<svg>
  <circle cx="{{cx}}"></circle>
</svg>

due to restrictions when using the SVG DOM API. Therefore, the ng-attr directive comes in handy with

<svg>
  <circle ng-attr-cx="{{cx}}"></circle>
</svg>

As a result, using the `ng-attr- directive in this scenario will appropriately set the value based on your binding. Now, what I have noticed new in the documentation are the following cases that have known to cause issues if you don't use ng-attr

John F.
  • 4,780
  • 5
  • 28
  • 40
  • Awesome, this is really helpful! I appreciate the explanation as well as the related issues. – Ron T Sep 13 '16 at 17:55