1

I am creating a form that contains multiple select options that should be populated from a database query. Each set of options for a dropdown comes from a different query. I am able to get 1 dropdown working fine.

I am curious to know if there is a best practice way off accomplishing this with multiple dropdowns/queries.

Is it better to merge multiple queries into one array? Is there a way to access the individual returns from my controller?

 getInfo();
function getInfo(){
// Sending request to EmpDetails.php files 
$http.post('databaseFiles/options.php').success(function(result){
// Stored the returned data into scope 
$scope.options = result;
console.log(result);
});
}
 <select class="form-control" ng-model="selectedDepartment" 
        ng-options="option.id as option.department for option in options ">
    <option value="">Select Department</option>
</select> 
dallas
  • 101
  • 13
  • 2
    If you have control over the php page, I would try and do all of the merging there. You don't want to make multiple http requests just to get the values for one drop down. Though if you do, you could could use `$q.all` to fire off several calls and have them return when all have been completed. Like so: https://stackoverflow.com/questions/31873979/angularjs-return-two-http-get-requests-only-when-resolved – dmgig Jun 01 '17 at 15:10
  • Got it working. However I have a ton of undefined values in each of my dropdowns now after merging the result array..any idea why this is or how to remove undefined values from an array before encoding in json? – dallas Jun 01 '17 at 16:42
  • Yes, for sure. You can use Array.filter ---> https://stackoverflow.com/questions/281264/remove-empty-elements-from-an-array-in-javascript – dmgig Jun 01 '17 at 22:19

0 Answers0