0

I've this JSON:

{
    "world": [{
        "name": {
            "en": "America"
        },
        "type": "continent",
        "children": [{
            "type": "state",
            "name": {
                "en": "Florida"
            }
        }, {
            "type": "state",
            "name": {
                "en": "Hawaii"
            }
        }]
    }, {
        "name": {
            "en": "Europe"
        },
        "type": "continent",
        "children": [

        ]
    }]
}

I need to do two select. The first contain the selection of type "continent", the other one based on the first must be showed if the first one children's are > 0 and contain the selection of the states.

1
  • what about some js ? where is your code ? Commented Sep 28, 2016 at 17:45

1 Answer 1

2

You can do this,

 <select name="client" ng-model="selectedRequest.continent" ng-options="c.name.en for c in clients.world" required></select>
 <select id="department" ng-model="selectedRequest.state" ng-options="d.name.en for d in  selectedRequest.continent.children"></select>

DEMO

EDIT

Updated fiddle disabling select if children is empty

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

5 Comments

your answer seems perfect.. how to hide the second select if there aren't children?
use ng-show and add your conditon, mark as answer if it has helped
ng-show="selectedRequest.continent.children > 0" doesn't work for me
@paolopolix did you check
if you check the console in your fiddle you'll look to some errors playing with it.. how can I solve them?

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.