Shikha thakur Shikha thakur - 1 year ago 85
AngularJS Question

add text before binded values while using ng-options

I have a scenario where i need to display options in dropdown with binded value and some text prefix to it

<select ng-model="rounds" ng-change="fnTopRating(rounds)" class="col-xs-4" ng-options="rounds for rounds in [1,2,3,4]">
<option value=''>round wise</option>
<option>Round {{rounds}}</option>

but here i am not getting round 1,round 2... in drop down instead i am getting 1,2,3,4...

I am not clear with what is happening .
Any help is appreciated.

Answer Source

Well, at first your syntax is a bit wrong. I'd recommend you to check the docs.

To add a prefix in your options you should use single quotes, like this:

<select ng-model="rounds" ng-change="fnTopRating()" class="col-xs-4" ng-options="'round ' + r for r in [1,2,3,4]">
   <option value label="round wise"></option>

Note: You just need to use $scope.rounds in your controller to get the selected item in fnTopRating() function, you don't need to pass it as parameter.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download