私はAngular.jsを学んでおり、次のコードがあります:
<button ng-class="{'btn pull-left',
duplicatesInList === true ? 'btn-warning': 'btn-success'}"
id="saveScoreButton" type="button" ng-click="add()"><button>
そして、構文に何か問題がありますが、何がわかりません...私がやりたいのは、リスト内の重複を見つけることです.重複がある場合は、保存ボタンのスタイルを変更してユーザーに警告したい(クラス btn-warning)。誰でも私を助けてくれることをとても嬉しく思います。よろしくお願いします。更新: コンソール ログ:
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
私にとってはかなり奇妙です。 解決策:
ng-class="duplicatesInList === true?
'btn btn-warning pull-left': 'btn btn-success pull-left'"
回答のコードも機能します(そして、IMOは私のソリューションよりも少し上手に書かれています:))