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> 

3
  • 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: stackoverflow.com/questions/31873979/… Commented Jun 1, 2017 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? Commented Jun 1, 2017 at 16:42
  • Yes, for sure. You can use Array.filter ---> stackoverflow.com/questions/281264/… Commented Jun 1, 2017 at 22:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.