Andrew Maddison

Flowerchild.

AngularJS Pipe in Expression Is a Filter Not Bitwise Or

If you come across a pipe (or bar) symbol in an angularJS expression, and don’t know what it means, it’s a Filter (effectively formatting options).

I had remarkable trouble googling for this problem, hence this keyword laden post. Basically if you come across a single pipe (or bar) symbol inside double curly brackets then you might think that this is a mistyped OR symbol, or if you’re a bit more JS savvy, a bitwise shift operator. In fact you have to remember that angular expressions are not vanilla javascript – they are parsed by angular itself and have their own syntax. The single pipe is in fact a filter operator which slightly confusingly is often used to format numbers, for example with localised decimal seperators.

I had to go on quite a google treasure hunt to find that out, so hopefully this can act as a bit of a signpost for the curious in future.

Comments