I have a different case here with ng-options
I have two modes for my app. New mode and Edit mode
I have SELECT input types for DISTRICTS and VILLAGES. The VILLAGES select is populated based on DISTRICT selection using ng-change event of DISTRICT select. This works fine in NEW mode.
But when in EDIT mode, the DISTRICT is correctly showing the value of ng-model. But the VILLAGE select input item is not showing the ng-model value. This is because, the village select does not have any items populated in it as the ng-change event of DISTRICT never triggers in EDIT mode.
I still want to show the ng-model value of VILLAGE as selected item in the drop down, even if it does not have any options in it. (in EDIT mode)
Any ideas of how this can be done? Please shed some light
Here the code below for DISTRICT select
<select class="form-control" name="district" id="field_district" ng-model="vm.apeksha.district" required
ng-change="vm.updateblocks(vm.apeksha.district)"
ng-options="x.malDistName as x.malDistName for x in vm.masterDistricts " >
Here is the code for VILLAGE select input item
<select class="form-control" name="village" id="field_village" ng-model="vm.apeksha.village"
ng-options="village.M as village.M for village in vm.villagelist track by village.M"
required >
<option value="{{ vm.apeksha.village }}">{{ vm.apeksha.village }}</option>
</select>
The option item is not shown even if there is value on "vm.apeksha.village"
In controller, we have a function which uses a factory to update the list of data corresponding to each DISTRICTS. Here is he code of controller
/**
* Update dropdown boxes of VILLAGES, THALUKS, PO AND BLOCS
* based on district selection
*/
vm.updateblocks = function(districtName) {
vm.blockslist = masterDataPopulator.getBlocksForDistrict(districtName);
vm.postofficelist = masterDataPopulator.getPostOfficesForDistrict(districtName);
vm.villagelist = masterDataPopulator.getVillagesForDistrict(districtName);
vm.thalukList = masterDataPopulator.getTaluksForDistrict(districtName);
};
Any ways to do this?