2017-08-02 24 views
0

どこが間違っていたのですか?また、編集や削除に使用したスクリプトに関する説明が必要です。これを説明する?アンカー機能が角型で機能していない

コード:

 <table border="1"> 
      <tr> 
       <td>ID</td> 
       <td>Name</td> 
       <td>Salary</td> 
      </tr> 
      <tr ng-repeat="faculty in facultymembers"> 
       <td><span ng-hide="editmode">{{faculty.id}}</span><input 
        type="text" ng-show="editmode" ng-model="faculty.id"></td> 
       <td><span ng-hide="editmode">{{faculty.name}}</span><input 
        type="text" ng-show="editmode" ng-model="faculty.name"></td> 
       <td><span ng-hide="editmode">{{faculty.salary}}</span><input 
        type="text" ng-show="editmode" ng-model="faculty.salary"></td> 
       <td><button ng-hide="editmode" 
         ng-click="editmode=true;editfaculty(faculty)">EDIT</button> 
        <button ng-show="editmode" ng-click="editmode=false">DONE</button></td> 
       <td><button ng-click="removefaculty($index)">REMOVE</button></td> 
      </tr> 
     </table> 

    </div> 

    <script> 
     var app = angular.module("myapp", []); 
     app.controller("mycont", function($scope) { 
      $scope.facultymembers = []; 
      $scope.addfaculty = function(faculty) { 
       $scope.facultymembers.push(faculty); 
       $scope.faculty = {}; 

      }; 
      $scope.editfaculty = function(index) { 
       $scope.editing = $scope.facultymembers.Indexof(index) 
      }; 
      $scope.removefaculty = function(index) { 
       console.log(index); 
       $scope.facultymembers.splice(index, 1); 
      } 
     }); 
    </script> 

</body> 
</html> 
+1

'Indexof'は' indexOf'に置き換える必要があります。 – 31piy

答えて

0

私はあなたが$インデックスによってトラックを逃したと思う: -

var app = angular.module("myApp", []); 
 
app.controller("myCtrl", function($scope) { 
 
    
 
    $scope.facultymembers = [{ 
 
     'id': 1, 
 
     'name': 'Test', 
 
     'salary': 2000 
 
     }]; 
 
     $scope.addfaculty = function(faculty) { 
 
     $scope.facultymembers.push(faculty); 
 
     $scope.faculty = {}; 
 

 
     }; 
 
     $scope.editfaculty = function(index) { 
 
     $scope.editing = $scope.facultymembers.Indexof(index) 
 
     }; 
 
     $scope.removefaculty = function(index) { 
 
     console.log(index); 
 
     $scope.facultymembers.splice(index, 1); 
 
     } 
 
});
<!DOCTYPE html> 
 
<html> 
 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> 
 
<body> 
 

 
<div ng-app="myApp" ng-controller="myCtrl"> 
 
    
 
<table border="1" class="table"> 
 
      <tr> 
 
      <td>ID</td> 
 
      <td>Name</td> 
 
      <td>Salary</td> 
 
      </tr> 
 
      <tr ng-repeat="faculty in facultymembers track by $index"> 
 
      <td><span ng-hide="editmode">{{faculty.id}}</span><input type="text" ng-show="editmode" ng-model="faculty.id"></td> 
 
      <td><span ng-hide="editmode">{{faculty.name}}</span><input type="text" ng-show="editmode" ng-model="faculty.name"></td> 
 
      <td><span ng-hide="editmode">{{faculty.salary}}</span><input type="text" ng-show="editmode" ng-model="faculty.salary"></td> 
 
      <td><button ng-hide="editmode" ng-click="editmode=true;editfaculty($index)">EDIT</button> 
 
       <button ng-show="editmode" ng-click="editmode=false">DONE</button></td> 
 
      <td><button ng-click="removefaculty($index)">REMOVE</button></td> 
 
      </tr> 
 
     </table> 
 
</div>

+1

downvoteを説明してください、スニペットが動作しています –

+0

ありがとうあなたのおかげで... – Pravin

+0

@Pravinあなたを歓迎します –

関連する問題