Is it safe to use ampersands (&) in AngularJS html templates
It's fine. The HTML5 spec explicitly allows unencoded ampersands if they don't look like a character reference (such as ©
). Sure, for some things like URLs it's better to be consistent and escape them. But for &&
with spaces around it, there's no chance that the browser will misinterpret the data, and &&
is significantly less readable.
Relevant Sections of the spec:
- https://www.w3.org/TR/html5/syntax.html#escapable-raw-text-elements
- https://www.w3.org/TR/html5/syntax.html#syntax-ambiguous-ampersand
I use ampersands in my Angular html templates too and never had a problem with them, but the best way to see if it's safe for you to use them is to just test their effect in a test app that resembles yours I guess...