0

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.

2
  • Its because of value="{{ [category.id , category.title] }} Commented Feb 5, 2016 at 10:35
  • Plz mark as answer if it is the right answer Commented Feb 5, 2016 at 12:23

1 Answer 1

2

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.titleand models.category.id.

Sign up to request clarification or add additional context in comments.

2 Comments

i want to show 1 and sport in different part with in my application view.
maybe it's better to show what you want then, because u said you want 1 sports in the value. But take a look at my answer above. Use the ng-options instead of a repeat. This way you can have the complete category inside your ng-model which you can use everywhere on your page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.