Reputation: 470
In my angularjs application view.html, I have following code as shown below:
<select ng-model="models.category">
<option ng-repeat="category in categories" value="{{ [category.id , category.title] }}">
</select>
When i access models.category using expression.
{{ models.category}}
The output is.
[1,"sports"]
But, all i want is to display is 1 and sports
in different part of my application view.
Upvotes: 0
Views: 37
Reputation: 2766
You could do this by doing the following
{{category.id + ' ' + category.title}}
I personally think it's even better to use ng-options if you use a select because the ng-model
used on the select is always a string if you use ng-repeat
<select name="mySelect" id="mySelect"
ng-options="option.title for option in categories track by option.id"
ng-model="models.category"></select>
and on another part of you application you can use the models.category.title
and models.category.id
.
Upvotes: 2