2017-03-22 38 views
0
app.controller("xyzController", ["$scope", "$location", "$window", "$http", function ($scope, $location, $window, $http) { 

    $scope.addTagList = []; 
    $scope.addTag = function() { 
     var branchid = $("#element").val(); 
     var list = branchid.split("|"); 
     var empid = list[0].trim(); 
     var employee_name = list[1].trim(); 

     $scope.addTagList.push({ 
      empid: empid, 
      employee_name: employee_name, 
     }); 
    } 

    $scope.RemoveAnswer = function (index) { 
     $scope.addTagList.splice(index, 1); 
    } 
}]); 

今天我面臨一個問題,像多個標籤框綁定角js ng-repeat然後標籤在html中顯示多個,但所有標籤想要舉行在javascript變量的數組中,但只獲得第一個值。以上代碼正確運行添加和刪除標籤。標籤框綁定與角js但不是所有值捕獲id在javascript

<input type="button" value="Add" class="form-control btn-sm btn-danger" ng-click="addTag()"/> 

<div id="tags" style="margin: 6px;font-size:10px;" ng-repeat="item in addTagList" class="label label-danger"><span >{{item.empid}} | {{item.employee_name}} </span> | <a><span ng-click="RemoveAnswer($index)">X</span></a> </div> </div> 

enter image description here

回答