javascript - What is the correct syntax in AngularJS' ng-options? -
i got array rest-service , trying create option/dropdown data.
$scope.reasons = [{ "languagelanguageid": { "languageid": 1, "lastupdate": "2015-05-08t11:14:00+03:00", "name": "eng" }, "returntext": "reason1", "returnreasonid": 1}, { "languagelanguageid": { "languageid": 1, "lastupdate": "2015-05-08t11:14:00+03:00", "name": "eng" }, "returntext": "reason2", "returnreasonid": 2}, { "languagelanguageid": { "languageid": 1, "lastupdate": "2015-05-08t11:14:00+03:00", "name": "eng" }, "returntext": "reason3", "returnreasonid": 3
}];
html
<div class="col-md-10"> <select ng-model="reasons" ng-options="p.reason (p.returntext + '('+p.returnreasonid+')') p in reasons"></select> </div> <div class="col-md-10"> <select ng-model="reasons" ng-options="p.returnreasonid p.returntext p in reasons"></select> </div>
you miss ng-app , controller declaration:
<div ng-app> <div ng-controller="todoctrl"> <div class="col-md-10"> <select ng-model="reason" ng-options="p.returnreasonid p.returntext p in reasons"></select> {{reason}} </div> </div> </div>
and controller:
function todoctrl($scope) { $scope.reasons = [{ "languagelanguageid": { "languageid": 1, "lastupdate": "2015-05-08t11:14:00+03:00", "name": "eng" }, "returntext": "reason1", "returnreasonid": 1 }, { "languagelanguageid": { "languageid": 1, "lastupdate": "2015-05-08t11:14:00+03:00", "name": "eng" }, "returntext": "reason2", "returnreasonid": 2 }, { "languagelanguageid": { "languageid": 1, "lastupdate": "2015-05-08t11:14:00+03:00", "name": "eng" }, "returntext": "reason3", "returnreasonid": 3 }]; }
edit:
i mading mistake. in ng-model put want store selected value. in ng-options put values can select. hope you.
http://jsfiddle.net/u3pvm/15559/
check docs more info:
Comments
Post a Comment