Total Pageviews

2013/11/18

AngularJS - How to remove unnecessary blank option in dynamic drop down list

Based on AngularJS - How to create dynamic drop down list this post, you had learned how to create a dynamic drop down list via AnguarJS.

Problem
But we found out a problem, AngularJS will create an empty option in the dynamic drop down list and will place at first location. It's not my expected result.

Solution
You can set a default value to your dynamic drop down list, then you can fix your problem. Here is code snippet:
1:      //query  
2:      $scope.query = function(){  
3:        var result = nss702rService.query('rest/', $scope.model);  
4:        result.then(function(response){  
5:         $scope.dpNos = response;  
6:         //if have more than one record in dpNos,  
7:         //then set the first option as its default value  
8:         if($scope.dpNos.length > 0){  
9:           $scope.model.dpNo = $scope.dpNos[0].uid;  
10:         }  
11:       });  
12:      };  

Check the result. You won't find the empty option in the dynamic drop down list


No comments: