I'm having some trouble understanding a dropdown functionality in Angular.
I've tried following these posts from StackOverflow but I'm stuck:
How can I populate a select dropdown list from a JSON feed with AngularJS?
Angular js Populate dropdown with JSON
The only way I was able to populate the dropdown is with all the values showing in every single row (defeating its purpose):
+
My code so far:
HTML:
<div align = "left" ng-controller='DemoCtrl'>
<select ng-model="tiposProduto" >
<option value="">Selecione o tipo de produto:</option>
<option ng-repeat ="selectedTestAccount in testAccounts" value="item.Id"> {{testAccounts}}>
</select>
</div>
Javascript:
<script src="js/app.js"></script>
<script>
app.controller('DemoCtrl', function ($scope, $http) {
$scope.selectedTestAccount = null;
$scope.testAccounts = [];
$http({ method: 'GET', url: '//localhost:8080/RestfulWebservice/rs/service/getTodosTiposProduto'
}).success(function (result) {
$scope.testAccounts = result.tiposProduto;
});
});
</script>
So, I'm not sure what the ng-repeat line should be doing. Both "items" and "selectedTestAccount" are undefined if I try to log them in the console.
The scope is this (the testAccount values are the ones I wanted to populate as rows):
Can someone please give me a hand?