0

So i have a full on application here is a run down:

<table class="table">
        <thead>
            <tr>
                <th>Photo</th>
                <th>Item Name</th>
                <th>Price</th>
                <th>Quantity</th>
                <th>Action</th>
                <th>Edit update</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td><input class="form-control" ng-model="contact.photo"></td>
                <td><input class="form-control" ng-model="contact.name"></td>
                <td><input class="form-control" ng-model="contact.price"></td>
                <td><input class="form-control" ng-model="contact.quantity"></td>
                <td><button class="btn btn-primary" ng-click="addContact()">Add Item</button></td>
                <td><button class="btn btn-info" ng-click="update()">Update</button></td>

            </tr>
        </tbody>
    </table>
        <ul ng-repeat="contact in contactlist" class="items-ul">
            <li>
                <div class="sector"><img class='photo-display'>{{contact.photo}}</img></div>
                <div class="sector">
                     <p class="info-mid"><span style="font-size:30px; padding:0px;">{{contact.name}}</span></p>
                     <p class="info-mid"><span style="color:deepskyblue;">Price: </span>{{1 * contact.price}}</p>
                     <p class="info-mid"><span style="color:deepskyblue;">Quantity Remaining: </span>{{1 * contact.quantity}}</p>

                </div>
                <div class="sector">

                     <p style="font-size:18px; padding:10px 0px 0px 0px;">Total: <span style="color:lightgreen;">${{contact.quantity * contact.price}}</span></p>
                     <hr>
                     Sold: <input class="form-control" ng-model="contact.sold"><button class="btn btn-primary" ng-click="addSold()">Enter</button>
                     <p>{{1 * contact.quantity - contact.sold}}</p>
                     <br>
                    <p><button class="btn btn-danger" ng-click="remove(contact._id)">X</button><button class="btn btn-warning" ng-click="edit(contact._id)">Edit</button></p>
                </div>

            </li>
        </ul>

So right in the ul div class sector, I have {{1 * contact.quantity - contact.sold}} and when i input numbers it does subtract but how can I store that updated number to my database. here is my controller function that I want to use.

Controllers:

 $scope.addSold = function(id){
    console.log(id);
    $http.put('/contactlist' + $scope.contact._id, $scope.contact.sold).success(function(response){
        refresh();
    });
};

Server js put:

app.put('/contactlist/:id', function(req, res){
var id = req.params.id;
console.log(req.body.name);
db.contactlist.findAndModify({query: {_id: mongojs.ObjectId(id)},
    update: {$set: {photo: req.body.photo, name: req.body.name, price: req.body.price, quantity: req.body.quantity}},
    new: true}, function(err, doc){
        res.json(doc);

  });
});

I think My error is in the server.js put but I am not really advanced in Angular and Node so I dont know how to accomplish this. Thank YOU

Gianni
  • 136
  • 1
  • 14
  • I guess what I am trying to do i be able to click the enter button grab the number in the input and update the {{contact.quantity}}. – Gianni May 17 '15 at 07:59
  • Not sure if it's any help, but you seem to be missing a '/' before adding the contact id to your server call from the client. – SirDemon May 17 '15 at 08:28
  • hmm that did fix a bug but the problem. The MEAN stack is soo hard ive been learning but I still cant figure out some small things – Gianni May 18 '15 at 06:24

0 Answers0