Using Regex In View
{{ str }}
Solution 1:
Since your question was "Why?", the answer is that expressions in interpolation blocks are not JavaScript expressions, but Angular expressions. They look a lot like JavaScript (on purpose), but Angular uses its own parser to parse the code.
That way it can do more than just evaluate the expression once: it can also do things like analyze the dependencies, so it can watch the ingredients and update when those ingredients change. It can also evaluate the expression relative to the $scope
, so that {{foo}}
returns $scope.foo
rather than a global variable called foo
(which in turn makes things like ngRepeat work).
When the Angular team implemented Angular expressions, they obviously didn't implement regular expressions. That's not surprising -- that kind of code should be in your controller anyway, where you can test it.
Post a Comment for "Using Regex In View"