0

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

populate dropdown AngularJs

The only way I was able to populate the dropdown is with all the values showing in every single row (defeating its purpose): Current dropdown+ 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):Scope returned

Can someone please give me a hand?

1
  • SelectedTestAccount should not be declared in controller. And what is item? Commented May 20, 2017 at 20:40

1 Answer 1

1

Just put "selectedTestAccount" inside expression in option.

<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"> {{selectedTestAccount}}>
</select>
 </div>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.