1

Here I have a select, where I want to repeat the contacts on the supplier.

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="AppCtrl">
    Hello {{name}}
    
    <div ng-repeat="supplier in suppliers">
        {{supplier.name}}
        
        <select ng-options="contact.id as contact.name for contact in supplier.contacts">
        
        </select>
    </div>
    
</div>
<script>
var app = angular.module('app',[]);
    
    //app.directive('appDirective', function() {});
    //app.factory('appService', function() {});
    
    app.controller('AppCtrl', ['$scope', function($scope){
        $scope.name = "dave";
        
        $scope.suppliers = [
        		{id: 0, name: "dave", contacts : [
            	{id: 0, name: 'c1'},
              {id: 1, name: 'c2'},
              {id: 2, name: 'c3'},
              {id: 3, name: 'c4'},
            ]},
            {id: 1, name: "Steve", contacts : [
            	{id: 0, name: 'c1'},
              {id: 1, name: 'c2'},
              {id: 2, name: 'c3'},
              {id: 3, name: 'c4'},
            ]}
        ]
    }]);

</script>

Here I have the controller.

How come this doesn't seem to work?

http://jsfiddle.net/gnosticdave/091vpadb/1/

2 Answers 2

2

contacts is part of each supplier - so your array is actually supplier.contacts

select ng-options="contact.id as contact.name for contact in supplier.contacts"
                                                           ^^^^^^^^^^^^^^^^^^^^

Also, ngOptions needs an ngModel

Demo: http://jsfiddle.net/091vpadb/3/

Sign up to request clarification or add additional context in comments.

1 Comment

Ng-model fixed it. Thanks
0

Change:

<select ng-options="contact.id as contact.name for contact in contacts">

to:

<select ng-options="contact.id as contact.name for contact in supplier.contacts">

1 Comment

Sorry, I forgot to put that in my code, but even with it, its still not working.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.