Question

How can I display two dropdown menus with the proper options using angular's ng-repeat directive?

Here's a JSBin

js:

 angular.module('myApp', [])
    .controller('MainCtrl', function($scope) {

      $scope.templates = {
        pages: ['home', 'about'],
        posts: ['blog', 'lab']

      };

    });

HTML:

 <div class="container" ng-controller="MainCtrl">
    <form action="" class="col-lg-12" >
       <select class="form-control" ng-repeat="template in templates.pages>
        <option value = "{{ template }}"> {{ template }}</option>
      </select>
      <select class="form-control" ng-repeat="template in templates.posts>
        <option value = "{{ template }}"> {{ template }}</option>
      </select> 
    </form>

  </div>
Was it helpful?

Solution

ng-repeat should be used in option tags. Also, close double quotes in your ng-repeat expression.

Here your fixed JSBin

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top