0

I am currently working on a project in which, I am fetching the data from server and adding(pushing) in the array for further process. And its working great. I face problem when I add an external data to the array with the data coming from server.

var quantity= ItemsValue[1];
$scope.product = [];
$http.get(___).success(function(data) {
    $scope.greeting = data ;
    $scope.product.push($scope.greeting);
}

I want to push "quantity" with the "$scope.greeting". I already tried different thing such as concatenation but failed.

I want data of array to be like this. For Example

$scope.product=[{ "greeting.name": "abc", "greeting.price": "50", "quantity":"1" }]

Name and Price came from server and quantity in added as an extra data to Array.

<tbody >
<tr ng-repeat="greeting in product" ><!--  -->
            <td class="cart_product">
                <img src={{greeting.Image}} alt="book image" ></td>
            <td class="cart_description">
                <h4>{{greeting.Name}}</h4></td>
            <td class="cart_price">
                <p>Rs. {{greeting.Cost}}</p>
            </td>
            <td class="cart_quantity">
                                <div class="cart_quantity_button">
                                    <a class="cart_quantity_up" href=""> + </a>
                                    <input class="cart_quantity_input" type="text" name="quantity" value="Itemsquantity" autocomplete="off" size="2">
                                    <a class="cart_quantity_down" href=""> - </a>
                                </div>
                            </td>
                            <td class="cart_total">
                                <p class="cart_total_price">Rs. {{greeting.Cost}}</p>
                            </td>
                            <td class="cart_delete">
                                <a class="cart_quantity_delete" ng-click="removeItem($index)"><i class="fa fa-times"></i></a>
                            </td>
                        </tr>

                    </tbody>

This is the code of client end.

Any way to push these things together...

1 Answer 1

1

You can just add it into the object by creating a new property

var quantity = ItemsValue[1];
$scope.product = [];
$http.get(___).success(function(data) {
    $scope.greeting = data;
    $scope.greeting.quantity = quantity;
    $scope.product.push($scope.greeting);
}
Sign up to request clarification or add additional context in comments.

2 Comments

I am using the greeting in view to display data
@ZiaUllahMinhas modified accordingly

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.