1

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!

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Vikram
  • 608
  • 1
  • 7
  • 18

1 Answers1

3

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.

Joe Clay
  • 33,401
  • 4
  • 85
  • 85
  • Thanks a lot Joe for the quick answer. I have to wait 5 more mins before I can accept it! – Vikram Mar 03 '17 at 15:25
  • @Vikram: Glad I could help :) I think this slips most people up at some point while they're working with Angular 1.x. – Joe Clay Mar 03 '17 at 15:33