0

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.

1
  • 1
    Don't use a repeater. <p>SubCatId :{{input.model.Category[0].SubCategory.SubCatId}}</p> Commented Sep 7, 2015 at 5:10

1 Answer 1

0

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>
Sign up to request clarification or add additional context in comments.

1 Comment

I doubt you want ng-model. More likely ng-bind

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.