0


I am creating a simple inventory management application using AngularJS, Firebase with AngularFire library.
I have a problem when trying to update Unit number when user does Import/Export action. I don't know how to retrieve the id / index of each product when running in a loop.
My intention is: User can choose product from autocomplete list (Angucomplete-alt library) to do Import/Export, then enter number of units. He can add the product to the list of products which will be used for 1 Import/Export. When he click "Change", the loop will run and update the unit number for each product.
Please help me with the function, thank you very much.
This is my sample at [Plnkr.co][1]

  [1]: http://plnkr.co/edit/UovmBcNjyk3w7FW3NbMC?p=preview

1 Answer 1

3

We can run two loops to match the product names and increment the unit. But more elegant way is to show them the products only that are availbe in inventory by using select option.

     <select class="form-control" ng-init="product.currProd = products[0]" ng-model="product.currProd" ng-options="prod.name for prod in products"></select>

And then adding the currProd property to each pushed product.

Change unit function can then be altered as below

      var obj = $firebaseArray(productRef);
      $scope.products=obj;

      $scope.changeUnit = function(){
        $scope.productList.forEach(function(prod){
        prod.currProd.unit=prod.unit;
        obj.$save(prod.currProd);
       });
    }

Here's the forked plunker

http://plnkr.co/edit/vGvMwqaXOoagqs0R4V2Y?p=preview

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you. But it just changes the data in local. Can you make it change the real data in Firebase?
Hi James i edited the plunker that would update in firbase array too. Please check it.
Thanks @Naveen Kumar N! However, use select option will have a disadvantage when I have a list of hundreds items, it's hard to scroll and select. Therefore, I apply angucomplete-alt library for autocomplete. Please help me to update your code because I can't get it done. I have updated my Plnkr.co at [plnkr.co/edit/UovmBcNjyk3w7FW3NbMC?p=preview] using Angucomplete-alt
Yeah, I have solved it myself. Thank you very much for your help #Naveen

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.