I have the folowing attribute on a div: ng-show="state.name === 'index'"
. I've also tried ng-show='state.name === "index"
, but I keep getting the following error:
Syntax Error: Token '
"index"
' is an unexpected token at column 16 of the expression[state.name === "index"]
starting at["index"]
.
Why?
Unexpected Token errors belong to SyntaxErrors. This error occurs when we try to call the code with the extra or missing character which does not belong to JavaScript family. In this tutorial, we will try to fix the Unexpected Token error.
Similarly, unnecessary use of any token will throw this type of error. We can remove this error by binding by following the programming rules of JavaScript.
Tokens: All the operator (+, -, if, else…) are reserved by the JavaScript engine.So, it cannot be used incorrectly .It cannot be used as part of variable names. Line terminators: A JavaScript code should end with semi-colon (;). Control characters: To control code, it is important to maintain braces ( { }) in a code.
This is a problem caused by AngularJS using jQuery and appears to be a known limitation (see issue 13771 ); jQuery treats colons as special selectors so ids with colons break the parser. Your options are to either override the form directive or move the apex:form tag outside of your Angular app, which is what I did.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With