如何在angularjs中突出显示所选行

时间:2018-12-24 05:05:20

标签: angularjs

在AngularJS中,我希望当用户从“主页”转到“详细信息页面”时突出显示表中的选定行。请问有人可以帮我怎么做

我尝试使用下面的代码来满足我的要求,但它不起作用

home.html

<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 });
    }
})

DetailsPage

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;
    }
});

1 个答案:

答案 0 :(得分:0)

无需在ng-class内使用方括号。像这样重构。

<div class="panel panel-primary" ng-class="{'panel-success':employee.id===selectedId}">