2015-11-26 120 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

找不到接受它的選項.. –