angularjs – anjularjs将值推送到嵌套的ng-repeat

前端之家收集整理的这篇文章主要介绍了angularjs – anjularjs将值推送到嵌套的ng-repeat前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个ng-repeat嵌套在另一个ng-repeat中.我想在单击按钮时将某些值推送到第二个数组
<div ng-repeat="vehicle in vehicleList">
  <div>{{vehicle.number}}</div>
  <input name="addName" value="add" ng-click="addVehicle(vehicle)"
  <div ng-repeat="categoryList in vehicle.category">
    <div>{{categoryList.name}}</div>
  </div>
</div>
I tried following code but it's not working
$scope.vehicleList=[];

$scope.addVehicle = function(){
 $scope.vehicleList.push({
   category:'car'
 });
}

谁可以帮我这个事.谢谢

<div ng-repeat="vehicle in vehicleList">
  <div>{{vehicle.number}}</div>
  <input name="addName" value="add" ng-click="addVehicle($index,vehicle)">
  <div ng-repeat="categoryList in vehicle.category">
    <div>{{categoryList.name}}</div>
  </div>
</div>

$scope.vehicleList = [];

$scope.addVehicle = function(index,vehicle) {
 $scope.vehicleList[index].category.push({
   name: vehicle
 });
};
原文链接:https://www.f2er.com/angularjs/143288.html

猜你在找的Angularjs相关文章