I've been diving into the world of Angular.js and came across this code snippet:
<button ng-class="{'btn pull-left',
duplicatesInList === true ? 'btn-warning': 'btn-success'}"
id="saveScoreButton" type="button" ng-click="add()"><button>
There seems to be a syntax error in there, but I can't quite pinpoint it... What I'm trying to achieve is to detect duplicates in a list and when found, notify the user by changing the style of the save button (class btn-warning). Any help would be greatly appreciated, thank you in advance. Update: Here's what the console logged:
Error: [$parse:syntax] http://errors.angularjs.org/1.2.16/$parse/syntax?p0=%2C&p1=is%20unexpected%2C%20expecting%20%5B%3A%5D&p2=17&p3=%7B'btn%20pull-left'%2CNaNuplicatesInList%20%3D%3D%3D%20true%20%3F%20'btn-warning'%3A%20'btn-success'%7D&p4=%2C%duplicatesInList%20%3D%3D%3D%20true%20%3F%20'btn-warning'%3A%20'btn-success'%7D
Quite puzzling for me. SOLUTION:
ng-class="duplicatesInList === true?
'btn btn-warning pull-left': 'btn btn-success pull-left'"
The solutions provided in other answers also work (and in my opinion are slightly better written than my own solution:) )