Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularjs trigger country state dependency
    text
    copied!<p>Can someone please help me make my example of Country/State drop down dependency work?</p> <p>I intentionally created JSON in this way because I want the dependency to be generic, so I would be able to apply it on any drop down while using only Meta Data and not HTML. </p> <p>Here's <a href="http://jsfiddle.net/kobiso/TsxTU/11/" rel="noreferrer">a link</a> to see an example of the code in JSFidlle</p> <p><strong>HTML</strong></p> <pre><code>Country:&lt;select data-ng-model="Countries" data-ng-options="country.id as country.name for country in Countries.items"&gt; &lt;option value=""&gt;Please select a country&lt;/option&gt; &lt;/select&gt; State: &lt;select data-ng-model="currentItem" data-ng-options="item.id as item.name for item in currentStates.items"&gt; &lt;option value=""&gt;Please select a state&lt;/option&gt; &lt;/select&gt; </code></pre> <p><strong>JavaScript Code:</strong></p> <pre><code>function Controller($scope) { var Countries = { "id": "field10", "items": [{ "id": "10", "StateGroupID":"0", "name": "United State" }, { "id": "2", "StateGroupID":"1", "name": "Canada" }] }; var States = { "id": "field20", "StateGroups": [{ "items": [{ "id": "1", "name": "Alabama" }, { "id": "2", "name": "Alaska" }, { "id": "3", "name": "Arizona" }, { "id": "4", "name": "California" }]}, [{ "id": "201", "name": "Alberta" }, { "id": "202", "name": "British Columbia" }, { "id": "303", "name": "Manitoba" }, { "id": "304", "name": "Ontario" }]] }; $scope.Countries = Countries; $scope.currentStates = States.StateGroups[0]; $scope.$watch('currentStates', function(value, oldValue){ //alert(value); //alert(JSON.stringify(value)); //$scope.currentStates = (value == "10") ? States.StateGroups[0] : States.StateGroups[1]; }); </code></pre> <p>} </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload