Following is a dropdown data-bound with AngualarJS:
<select name="lineCode" class="form-control input-sm"
ng-model="monitoringProbe.tdmCapture.selectedTDMCard.layer1Properties.lineCode"
ng-options="l.id as l.name for l in monitoringProbeTDMCaptureData.lineCodes"
required >
</select>
I populate the ng-options as follows:
virtualServerMonitoringProbeService.comboProperties().query({},{itemType:1, interfaceType: interfaceType}).$promise.then(
function(result){
monitoringProbeTDMCaptureData.lineCodes = result;
},
function(error){
messageNotificationFactory.setNotification('error', error.data.message);
}
);
According to the following post, when there's no value in ng-model to match the items in the dropdown. Why does AngularJS include an empty option in select?
Therefore I force the first element in the list to be the selected value, as follows:
virtualServerMonitoringProbeService.comboProperties().query({},{itemType:1, interfaceType: interfaceType}).$promise.then(
function(result){
monitoringProbeTDMCaptureData.lineCodes = result;
tdmCapture.selectedTDMCard.layer1Properties.lineCode = monitoringProbeTDMCaptureData.lineCodes[0];
},
function(error){
messageNotificationFactory.setNotification('error', error.data.message);
}
);
But still the dropdown selection is empty. At run time this is how it looks like:
<select name="lineCode" class="form-control input-sm ng-pristine ng-valid ng-valid-required" ng-model="monitoringProbe.tdmCapture.selectedTDMCard.layer1Properties.lineCode" ng-options="l.id as l.name for l in monitoringProbeTDMCaptureData.lineCodes" required="">
<option value="?" selected="selected"></option>
<option value="0">AMI</option>
<option value="1">B8ZS</option>
</select>
Anything wrong with this code?