2015-11-26 77 views
0

我想编辑表中的一行数据。当我点击该行时,它弹出所需的视图,但它不能拉出相关数据进行编辑。任何人都可以尝试找到问题。我猜它与$ routeParams和表行的相关索引有关。加入了我的运动员。angularjs表行编辑问题

app.controller("editController", ["$scope", "$location", "$routeParams", "listService", function($scope, $location, $routePartam, listService) { $scope.data = listService.getDepartments(); //$scope.id = $routeParams.id; //alert($route.current.params.id); 
 
//alert("test"+ "$routeParams"); //$scope.Item=listService.getDepartments()[parseInt($routeParams.id)]; $scope.Item=listService.getDepartments()[0]; // saving an existing items $scope.save = function() { listService.editDepartments(0,{dialnumber:$scope.Item.dialnumber,department:$scope.Item.department,level:$scope.Item.level}); 
 
//listService.editDepartments(parseInt($routeParams.index),{dialnumber:$scope.Item.dialnumber,department:$scope.Item.department,level:$scope.Item.level}); //Saving code $location.path("/Items"); }; $scope.cancel = function() { $location.path("/Items"); 
 
};

http://plnkr.co/edit/ez0s66S9bmO0jt8Nb6BR?p=info

+1

你应该格式化张贴您的代码时,你就会有有人更好地扫描它并发现问题。 –

回答

0

你几乎得到了它......它是一个错字:

function($scope, $location, $routePartam, listService) { 

看到了什么?它说$routePartam代替或$routeParams,让你的editController代码可能是这样的,检查第一行:

function($scope, $location, $routeParams, listService) { 
    $scope.data = listService.getDepartments(); 
    //$scope.id = $routeParams.id; 

    //alert($route.current.params.id); 

    //alert("test"+ "$routeParams"); 
    //$scope.Item=listService.getDepartments()[parseInt($routeParams.id)]; 
    var id = $routeParams.id; 

    $scope.Item=listService.getDepartments()[id]; 
    // saving an existing items 
    $scope.save = function() { 
     listService.editDepartments(id,{dialnumber:$scope.Item.dialnumber,department:$scope.Item.department,level:$scope.Item.level});  

退房固定plunker:http://plnkr.co/edit/oZrQaPUNTOOxDt8kqU5t?p=preview

+0

非常感谢你..我没有意识到有一个错字 –

+0

好极了,欢迎来到SO,最好的表达方式就是接受答案(复选标记):) – Roberto

+0

找不到接受它的选项.. –