2017-08-03 78 views
0

當我添加任何數據我得到的文本框中的值,而不是得到它在span.And還後的數據被添加我正在完成按鈕,而不是讓更新button.Find的我完整的代碼在這裏:https://jsfiddle.net/GowthamG/jL5oza04/ 有什麼錯誤?編輯功能沒有正確的角度JS工作

<script type="text/javascript"> 
var app=angular.module("mainapp",[]); 
app.controller('mycontrol',function($scope){ 
    $scope.filters=[]; 
    $scope.add=function(filter){ 
     $scope.filters.push(filter); 
      $scope.filter={}; 
     }; 
     $scope.update = function (index) { 
      $scope.editing = $scope.filters.indexOf(index); 
     }; 



<table border="2"> 
    <tr> 
     <td>FirstName</td> 
     <td>LastName</td> 
     <td>Fees</td> 
     <td>E-Course</td> 
    </tr> 
    <tr ng-repeat="filter in filters track by $index"> 
     <td><span ng-hide="update">{{filter.fname}}</span> 
      <input type="text" ng-show="update" ng-model="filter.fname"> 
     </td> 
     <td><span ng-hide="update">{{filter.lname}}</span> 
      <input type="text" ng-show="update" ng-model="filter.lname"> 
     </td> 
     <td><span ng-hide="update">{{filter.ffees}}</span> 
      <input type="number" ng-show="update" ng-model="filter.ffees"> 
     </td> 
     <td><span ng-hide="update">{{filter.eroll}}</span> 
      <input type="text" ng-show="update" ng-model="filter.eroll"> 
     </td> 
     <td> 
      <button ng-hide="update" ng-click="update = true; update($index)">Update</button> 
      <button ng-show="update" ng-click="update = false">Done</button> 
     </td> 
     <td> 
      <button ng-click="remove($index)">Remove</button> 
     </td> 
    </tr> 
</table> 
+0

,其中從HTML叫你的add方法?此外,我沒有看到你的更新變量在添加的代碼中的任何地方得到更新。請發佈完整的代碼。您的HTML和控制器代碼中似乎也有錯誤,但也不完整。 – Shahzad

+0

如果我上傳完整的代碼,它表明你有後最大的代碼,我不能發佈問題 –

+0

請創建一個小提琴或plunkr然後。 – Shahzad

回答

0

您的功能添加到隱藏輸入初始化的$scope.update值。現在,這些值將以更新按鈕顯示在一個範圍內。

$scope.add=function(filter){ 
    $scope.filters.push(filter); 
     $scope.update=false; 
    }; 

工作演示https://jsfiddle.net/kz8uLg10/2/