【发布时间】:2014-09-11 19:59:37
【问题描述】:
我是 angularjs(和一般编程)的新手,遇到了麻烦。我正在跟随教程并尝试创建一个表格并在单击时突出显示特定行。我的控制台正在记录一个错误,单击该错误时会将我带到此处:语法错误:令牌“未定义”位于从 [{4}] 开始的表达式 [{3}] 的第 {2} 列。控制台中的原始错误是: [$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>
【问题讨论】:
-
根据错误(和您的示例),您在 ng-class 末尾缺少
}。
标签: javascript angularjs syntax ng-class