-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Ternary operator $parse error #8484
Comments
It works if you surround the assignments with brackets: http://jsfiddle.net/pLMS6/1/ |
It's just the precedence and associativity of operators. <button ng-click="foo ? (bar = true) : (bas = false)">Click</button> |
Yes but I think foo ? (bar = true) : (bas = false)
Ref : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence |
Looks like a bug and one that was present since the introduction of the ternary operator |
I feel like this is probably a WONTFIX, angular expressions aren't javascript, and can't be expected to be a bugfree javascript interpreter. |
But it could be quite a straightforward fix, if it is just about setting the precedence? |
That being said we are trying to move away from assignment in expressions and a simple workaround is to call functions instead:
will work |
…right expressions Closes angular#8484
Properly handle assignemnts inside ternary operators Closes angular#8484
@petebacondarwin you beat me on this. The question is if within the ternary operator expressions should we allow assignments or a filter chain |
I quite like the idea of filterChain actually! |
Simple demo:
Error :
[$parse:syntax] Syntax Error: Token 'undefined' expected : at column null of the expression [foo ? bar=true : bas=true] starting at [foo ? bar=true : bas=true]
Fiddle : http://jsfiddle.net/basarat/pLMS6/
Angular Version :
1.2.21
I believe its feature not implemented.
The text was updated successfully, but these errors were encountered: