Why is AngularJS complaining about an unexpected token in an expression when I try to use a string? Why is AngularJS complaining about an unexpected token in an expression when I try to use a string? angularjs angularjs

Why is AngularJS complaining about an unexpected token in an expression when I try to use a string?


ng-show takes an "AngularJS statement." This type of statement only has an == operator, but this operator behaves like ===. It's a bit confusing, but handy in that you cannot shoot yourself in the foot with weird type coercion.


I found the problem. Instead of "state.name==='index'", I should have written "state.name=='index'". pkoziowski.opensource was right, in that you can't use conditional statements, but what they mean by that, is that you can't use if statements, or any control flow statements for that matter, so you couldn't do this:

<span ng-init="if(state.name == 'o'){doFoo();}">o</span>


A new answer is now possible for this question: you may be using an old version of AngularJS, because newer versions do not have this.

See here a repro of OP's issue with the latest version at the time the question was asked (1.1.0):

angular.module("demo", [])  .controller("myctrl", function($scope) {    $scope.state = { name: "test" };  });
<script src="https://code.angularjs.org/1.1.0/angular.js"></script><div ng-app="demo" ng-controller="myctrl">  (this snippet explicitly errors out, reproducing OP's issue)<br>  <input ng-model="state.name">  <div ng-show="state.name === 'test'">visible when "test" is in the input</div>  Debug info: <pre>{{state | json}}</pre></div>