如何在这个简单的angularjs网格中选择第一行

时间:2017-09-01 17:06:28

标签: angularjs

我在

中收到员工数据的回复
$scope.employeeData = response.data;

如何将第一行设为默认选择

  <tr ng-repeat="row in employeeData">
                <td>
                    <a ng-click="Test(row)"> {{row.employeeName}}</a>
                </td>
                <td>{{row.employeeStatus}}</td>
                <td>{{row.employeeDesignation}}</td>
            </tr>

1 个答案:

答案 0 :(得分:1)

$scope.SelectedRow = response.data[0]


var test  = function(row) {$scope.SelectedRow = row};

只需手动选择控制器中的行,然后在您的控制器中根据需要连接选定的行,或者如果您希望测试启动,您可以执行类似的操作

test(response.data[0]);

var test = function(row) {$scope.SelectedRow = row;}

******* ****** EDIT

app.controller("fooController", ["$scope", "dataService",  function ($scope, dataService) {

$scope.SelectedRow;//the selected row youwant to show
$scope.employeeData; //your data to display

self.test = function(row){ $scope.SelectedRow = row;}

//call your service to get your data

    dataService.GetData().then(function(result){
    $scope.employeeData = response.data;
    test(response.data[0]);//this will fire on "page load" 
    });


    }]);