angularjsangularjs-ng-if

Error using array function in ng-if


This sounds very simple but I have been struggling with it!

In AngularJs 1.4, I have an ng-if which is using array's some() function. I get syntax error

Syntax Error: Token '>' not a primary expression at column ...

when doing this.

My HTML is:

<!-- DOES NOT WORK!! -->
<div ng-if="myArr.some(x => x == 'car')">
  Function check fine!
</div>

Here is the plunk https://plnkr.co/edit/v5SLIU5dQdIlpP5sCmzR

Thanks!


Solution

  • Angular uses its own built-in parser to evaluate the expressions in your templates, which does not support function declarations. You should pull the logic out of your template and into the controller, and then bind to it.