When using two select elements, the options in the second select must depend on the value selected in the first select. For example, I want to populate a list of companies (in the 2nd <select>
) based on a particular service chosen in the 1st <select>
:
<div ng-controller="GetCompaniesByService as class">
<select ng-options="service.name for service in class.services" ng-model="selectedService"></select>
Chosen service_id: {{ selectedService.id }}
<select ng-options="company.name for company in class.companies" ng-model="selectedCompany"></select>
</div>
In order to access the current selectedService.id value from the model within the controller, you can dynamically load data via ajax from a URL like this:
$http.get('http://127.0.0.1:3000/service/'+selectedService.id)
This data can then be used to populate the options in the second <select>
.