javascript - How to bind an array to select by Angularjs? -


i trying bind object array select drop down, cannot figure out how make work, can suggest how make work?

html:

<div ng-app ng-controller="displayctrl"> <select ng-model="eventname" ng-options="name.event name in eventnames">     <option value="">select event</option> </select> <p>currently selected: {{eventname.description}} </p></div> 

angularjs:

function displayctrl($scope) { $scope.eventnames = [{     event: "function a",     description: "gaming" }, {     event: "function b",     description: "basketball" }, {     event: "function c",     description: "football" }, {     event: "function d",     description: "dancing" }]; $scope.eventname = $scope.eventnames[1].event;} 

http://jsfiddle.net/ztabs/

with object-arrays, angular store real object in model variable. preselection should same, thus:

$scope.eventname = $scope.eventnames[1].event; 

should be:

$scope.eventname = $scope.eventnames[1]; 

see:

http://jsbin.com/uyujudo/1/


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -