Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
128
rated 0 times [  130] [ 2]  / answers: 1 / hits: 17727  / 10 Years ago, mon, august 11, 2014, 12:00:00

I have this dropdown in my page



<select 
ng-options=col.col_id as col.col_name for col in meta_data.x_cols
ng-model=obj.x>
</select>


Since the model is set to obj.x, I can access it using $scope.obj.x in any $scope function.



Naturally, it gives the value of the selected option. Is there any way by which I can get selected text as well? for e.g. bind obj.x to and obj.x_text to the text of selected option.


More From » angularjs

 Answers
61

If you bind col and not col.col_id:



<select 
ng-options=col as col.col_name for col in meta_data.x_cols track by col.col_id
ng-model=obj.x>
</select>


you will be able to access both col_id and col_name from $scope.obj.x:



$scope.obj.x.col_id
$scope.obj.x.col_name

[#69832] Friday, August 8, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
samara

Total Points: 326
Total Questions: 106
Total Answers: 103

Location: Cook Islands
Member since Thu, May 21, 2020
4 Years ago
;