在AngularJS中,我希望当用户从“主页”转到“详细信息页面”时突出显示表中的选定行。请问有人可以帮我怎么做
我尝试使用下面的代码来满足我的要求,但它不起作用
<div ng-repeat="employee in employeeList">
<div class="panel panel-primary" ng-class="{'panel-success' : employee.id===selectedId}">
<div class="panel-heading">
<h3 class="panel-title">{{employee.name}}</h3>
</div>
</div>
</div>
routerApp.controller('EmployeeController', function ($scope, $state,dataService) {
$scope.selectedId = dataService.getId();
$scope.viewEmployee = function (employeeId) {
$state.go('employeeDetails', { employeeId: employeeId });
}
})
routerApp.controller('EmployeeDetailsController', function ($scope, $rootScope, $state,dataService) {
$scope.goBack = function () {
dataService.setId($stateParams.employeeId);
$state.go('employeeList');
}
})
routerApp.service("dataService", function () {
var employeeId;
this.setId = function (id) {
employeeId = id;
}
this.getId = function () {
return employeeId;
}
});
答案 0 :(得分:0)
无需在ng-class
内使用方括号。像这样重构。
<div class="panel panel-primary" ng-class="{'panel-success':employee.id===selectedId}">