As I understand AngularJS sets default value when using ng-model
directive. I need to populate select element with only valid options which retrieved by $http.get
. The problem is that on top of all valid elements I have one dummy element vith value ?
. How to get rid of it?
<select id="environment" name="environment_name" ng-model="environment" ng-options="e.name for e in ENVIRONMENTS" required>
</select>
$scope.ENVIRONMENTS = [];
$http.get("/getEnvironments").success(function(data){
data.forEach(function(el){
$scope.ENVIRONMENTS.push(el);
});
}).error(function (data) {
$scope.showErrorMsg("Cannot get ENVIRONMENTS.");
});
$scope.environment = $scope.ENVIRONMENTS[0];