0

I want to make a products list where I get the products name and Add Products price & their PV And BV.

Here i saved JSON Data in $scope :

$scope.products = [
 {"id":1,"name":'SP0300370 Nutrient Super Calcium powder',"price":21,"PV":18,"BV":18},
 {"id":2,"name":'SP0300315 Calcium Powser with Metabolic Factors',"price":25,"PV":21,"BV":21},
 {"id":3,"name":'SP0300372 Super Calcium Powder for Children',"price":26.5,"PV":23,"BV": 23}];

Angular binded html :

<div ng-controller="FormController">
    <div class="form-group">
      <label class="control-label col-sm-2">Products</label>
        <input auto-complete ui-items="products" ng-model="product">
      <button type="button" ng-click="ProductList()" class="btn btn-success col-sm-offset-10 col-sm-2">Add Product</button>
    </div>

This is the form Through Which I want to make The Products selectable. Thank you

2
  • What is your question exactly? @Nouman Saif Commented Mar 7, 2016 at 8:59
  • I am sorry If I can't elaborate exactly. Have you seen a software at Shopping centers and etc? where they enter a product name or code for products and the software enlists the products and their prices? thats What I want to make Commented Mar 7, 2016 at 9:03

1 Answer 1

3
 <div ng-repeat="p in products" ng-click="p.selected=!p.selected" ng-class="{'selected-product':p.selected}"> 
      <input type="text" ng-model="p.name" ng-value="p.name"> 
      <input type="text" ng-model="p.price" ng-value="p.price"> 
      <input type="text" ng-model="p.PV" ng-value="p.PV">
 </div>

is to show your array in angularjs and you can edit. And the following normal push operation will add your product to the list.

var newObject = {name : "A", price: 4, PV: 2323, selected: false}
$scope.products.push(newObject)

If you want to do much deeper operations and if you have not so much experience, i can propose you to use a grid framework like ui-grid

You see here a working plunker

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

5 Comments

Hello. I tried this but I can't understand Why have you used the ng-Click on a div? Like how would it work then?
if the element is clicked, its property selected will be changed (if true->false;if false->true) so you can assign other properties to products with selected=true. Now i updated my answer by e.g. assigning new class for selected products (using ng-class directive). so you can change background-color of selected product etc.
Literally Can't understand this :( Can You explain me this Step by step? And Where do I have to add them in my code?
updated my answer with a plunker. Just check that out and try to read the documentations of angular
Doesn't Accept new data

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.