查看未将数据数组发送到AngularJs控制器

时间:2017-09-07 23:20:01

标签: angularjs

查看

<div ng-repeat="supplie in supplies">
<div class="i-checks" >
    <input id="boxInsumo{{supplie.id_supplies}}" type="checkbox" name="name" ng-model="dataSupplies.name" class="form-control-custom col-lg-2" ng-true-value="{{supplie.name}}">
    <label for="boxInsumo{{supplie.id_supplies}}">{{supplie.name}}</label>
        <div class="form-group" >      
            <label>Cantidad</label>
            <input type="number" placeholder="cuantity" name="cuantity" ng-model="dataSupplies.cuantity" class="form-control form-control-sm col-lg-5">
        </div>
    </div>                              
</div>

<div><button ng-click="formSupplies(dataSupplies)">SEND</button></div>

/ ********************************************** *

控制器angulajs

$scope.formSupplies = function (dataSupplies) {
        console.log(dataSupplies);
    }

结果 未定义

1 个答案:

答案 0 :(得分:0)

如果耗材不属于$ scope,则不适用于ng-repeat,并且它不能用作方法参数。

此外,您的ng-repeat没有绑定到某些变量。而不是:

<input type="number" placeholder="cuantity" name="cuantity" ng-model="supplie.cuantity" class="form-control form-control-sm col-lg-5">

您可能正在使用:

<input type="number" placeholder="cuantity" name="cuantity" ng-model="dataSupplie.cuantity" class="form-control form-control-sm col-lg-5">

您似乎正在使用supplie,您应该使用dataSupplie(或反之亦然)。解决该问题后,您可以对所选项目使用$ filter:

  $scope.isSelected = function(product) {
    return product.selected;
  };

  $scope.formSupplies = function() {
    var filteredSupplies = 
        $filter('filter')($scope.dataSupplies, $scope.isSelected);
  };

示例:https://codepen.io/zameb/pen/KvjqON