I wrote an $http.get function to extract data stored in a database.
I would like to use the database data in a dropdown function in AngularJS. Now this means that I have to create a new $scope JSON data variable and store the actual database data in it just so I can access it in my HTML page.
<select popover="Choose your input drug, type to filter list of drugs" data-ng-model="currentData"
data-ng-options="name for name in ourDataName" style="width:300px;" convert-to-number >
</select>
ourDataName in data-ng-options is the variable I defined inside the controller as $scope.ourDataName, and it is supposed to have all the drug names inside it. It is possible for me to do what is written inside the get function below; however, the problem is that there are over 100 drug names:
$http.get(URL).success(function (data) { //Note URL is where I stored my database. I did not put it for privacy reasons
$scope.ourDataName =
[
data[1].drug_name,
data[2].drug_name,
data[3].drug_name
]
});
I tried to put a for loop over the JSON data as such:
for(var i=0; i<100;i++)
{
$scope.ourDataName =
[
data[i].drug_name
]
}
The problem is it ended up showing the 100th drug name only since it shows what the loop ends at.
I am out of solutions. Is there any way to loop through the database and store them in a new variable without having to go over each as I did at first?