我是angularjs(和一般编程)的新手并且遇到了麻烦。我正在按照教程进行操作并尝试创建表格并在单击时突出显示特定行。我的控制台正在记录一个错误,点击后会把我带到这里:语法错误:令牌'undefined'位于表达式[{3}]的第{2}列,从[{4}]开始。控制台中的原始错误是:[$ parse:syntax] http://errors.angularjs.org/1.2.23/ $ parse / syntax?p0 = undefined& p1 = is%20unexpected%2C%20expecting%20%5B%7D%5D& p2 = null& P3 =%7Bselected%3A%20%24index%3D%3DselectedRow&安培; P4 =%7Bselected%3A%20%24index%3D%3DselectedRow
app.js
app.controller('RestaurantTableController',['$scope', function ($scope){
$scope.selectedRow = {};
$scope.directory= [{name:'The Handsome Heifer', cuisine:'BBQ'},
{name: "Green's Green Greens", cuisine:'Salads'},
{name:'House of Fine Fish', cuisine: 'Seafood'}];
$scope.selectRestaurant=function(row){
console.log('restaurant test');
$scope.selectedRow = row;
};
}]);
index.html:
<table ng-controller="RestaurantTableController">
<tr ng-repeat="restaurant in directory" ng-click ='selectRestaurant($index)' ng-class='{selected: $index==selectedRow'>
<td>{{restaurant.name}}</td>
<td>{{restaurant.cuisine}}</td>
</tr>
</table>
答案 0 :(得分:1)
看起来你错过了ng-class值中的右括号:
ng-class='{selected: $index==selectedRow}'