Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I'm having JSON array. I need to get particular parameter value using ng-repeat in angularjs. I tried using filters and other ways but i didn't got values.

Here is my JSON

{
    "UserId":0,
    "Name":null,
    "ResponseStatus":null,
    "Category":[{
        "Id":0,
        "CategoryName":"Category 1",
        "Property":0,
        "SubCategory":{
            "SubCatId":"5600",
            "SubCatName":"Sub1"
        }
    }]
}

When i used <p data-ng-repeat="(key,data) in input.model.Category[0].SubCategory">{{key}} :{{data}}</p> It giving result like this.

<p>SubCatId :5600</p>
<p>SubCatName :Sub1</p>

But i want only SubCatId :5600 using ng-repeat because i want to display this two values in different place.

share|improve this question
1  
Don't use a repeater. <p>SubCatId :{{input.model.Category[0].SubCategory.SubCatId}}</p> – Phil Sep 7 '15 at 5:10

Why using an ng-repeat if you only want to show one element (Category at position 0 and/or subCatId) ?

If you only want to show the SubCatId of the SubCategory of the first Category, this simple syntax should work :

<p ng-model="input.model.Category[0].SubCategory.SubCatId"></p>

The only multi-valuable element in your JSON is Category, so if you want to show all the Category[x].SubCategory.SubCatId, the following syntax should do the job :

<p ng-repeat="category in input.model.Category">SubCatId :{{ category.SubCategory.SubCatId }}</p>
share|improve this answer
    
I doubt you want ng-model. More likely ng-bind – Phil Sep 7 '15 at 5:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.