1

How to populate pModel(50gm,100gm,250gm) in drop down using Angular JS

$scope.products=
{
"shopId" : "569df5c1d08598371e9b5ad5",
"mProId" : "569e07ccd08598371ebe5409",
"priceTag" : [
        {
            "pModel" : "50gm",
            "priceTagId" : 1,

        },
        {
            "pModel" : "100gm",
            "priceTagId" : 2,

        },
        {
            "pModel" : "250gm",
            "priceTagId" : 3,

        }
    ]
}

I am doing in this way.I dont know how it wont populate .Please help me to populate this one. This is my code

<select class="form-control" id="pricetags" ng-model="selectedPriceTag" 
    ng-options="product.priceTag.pModel for product in products" > 
</select>
1
  • I am not clear if you are repeating product or price-tags.... if products then I think it should be product.priceTag[0].pModel and if you want product and then price tags as its child then you will have to use group syntax Commented Jun 16, 2016 at 13:52

3 Answers 3

3

Here is a Plunker Demo

The problem is because you need to iterate through the priceTag property in products.

I recommend you update your code to the following

<select class="form-control" id="pricetags" ng-model="selectedPriceTag" 
ng-options="priceTag.pModel for priceTag in products.priceTag" > 
</select>
Sign up to request clarification or add additional context in comments.

Comments

0

try this

  <select class="form-control" id="pricetags" ng-model="products.selectedPriceTag">
    <option ng-repeat="product in products.priceTag" value="{{product.priceTagId}}">{{product.pModel}}</option>
  </select> 

Comments

0

You're using the ng-options syntax for arrays, but you're trying to select from $scope.products, an object. Modify your code so it iterates through the priceTag array in the $scope.products object..

<select class="form-control" id="pricetags" ng-model="selectedPriceTag" 
ng-options="priceTag.pModel for priceTag in products.priceTag" > 
</select>

Not sure if that's what you're looking for, but it should work!

Comments

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.