Push the input values ​​of ng-repeat into the array with Angu…

I have a ng-repeat
displaying a list of products
with an input each. I want to be able to push the value of each input together with a parameter from every item into a new array to create an order.

So far I managed to do it individually, but not all together.

Here’s my HTML:


Add items

And the function:

$scope.singleorder = [];

$scope.insert = function(nom, basket){
    'product': nom,
    'number': basket

I assume the issue has to do with keeping track of the different models of the inputs on each repeat, but I don’t know how to deal with it.

I’ve also tried adding each item individually using ng-change
on the input, but it will push an object on every change, duplicating the item on every change, so it won’t work.

Any tips?

The trick would be to have an input for each
repeated element in ng-repeat

Add items

will loop over products and insert in singleOrder
when basket has been set:

$scope.insert = function() {
    for (var i = 0; i < $scope.products.length; i++) {
        if ($scope.products[i].basket) { // if input has been set
              'product': $scope.products[i].nom,
              'number': $scope.products[i].basket

JSFiddle demo

Hello, buddy!稿源:Hello, buddy! (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 前端开发 » Push the input values &ZeroWidthSpace;&ZeroWidthSpace;of ng-repeat into the array with Angu…

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录