Krishna Patel
Krishna Patel

Reputation: 275

How to add new row from database in angularjs?

I want to add new row in table.Where table data is coming from database.which is as follow..

<div class="form-group form-horizontal" id="item" style="margin: 5px;">
    <label class="col-xs-2 control-label">Enter Barcode:</label>
    <div class="col-xs-2 selectContainer">
        <input type="text" class="form-control" ng-model="barcode" placeholder="enter barcode" />
    </div>
    <label class="col-xs-1 control-label">Quantity</label>
    <div class="col-xs-2 selectContainer">
        <input type="text" class="form-control" ng-model="qnt" ng-blur="putQnt()" placeholder="enter quantity" />
    </div>
    <button class="col-xs-1 btn btn-primary" ng-click="getInfo()">OK</button>
    <button class="btn btn-primary" ng-click="addItem()">Add Item</button>
</div>

Here I've to add barcode and quantity from barcode the select query would be fired and I get the data in one row. It's angularjs,

$scope.getInfo=function(){
        $http.get("../POS_System/widget/bill.php?barcode="+$scope.barcode).success(function(data){
           $scope.data=data;  
        }); 
      $scope.list={};
    }

Now when I'm adding new row it's overwrite the data.I didn't get the combine data.so what to do for adding new row from database according to it's barcode entry.Give me some suggestion for addItem() function.

Upvotes: 1

Views: 75

Answers (1)

Suresh Kamrushi
Suresh Kamrushi

Reputation: 16086

You can do like this:

$http.get("../POS_System/widget/bill.php?barcode="+$scope.barcode).success(function(data){
    var tempvar = data;
    var len = (tempvar.length);
    if(len>0) {
         for(var loop=0;loop<len;loop++) {
             $scope.data.push(tempvar[loop]);
    }  
        }); 

Upvotes: 1

Related Questions