1

I am outputting a list in angular from an object.

The object can contain anywhere from 0 - 100 items and the design I have to work to use the word for the numbers as the list item name.

E.g. currently:

<li ng-repeat="result in results">
    {{ $index }}
</li>

Will return 0,1,2,3 etc. But I need to instead show one, two, three...

Is there a simple way of doing this?

Lovelock
  • 7,689
  • 19
  • 86
  • 186

1 Answers1

1

You could simply do {{$index +1}}.

Then apply a custom filter to the this number. See Angular directive/service to convert number into words (need in Angularjs)? for creating a custom filter that converts a number to a word.

Community
  • 1
  • 1
Ben
  • 2,441
  • 1
  • 12
  • 16
  • I need the word value, so One two three, not 1 2 3. – Lovelock Mar 27 '17 at 15:48
  • My mistake, you'd have to write a custom filter to display it as a word. Unfortunately there are no built-in AngularJS filters for doing that. I'm sure you could easily find an example online of a custom filter that translates a number into its respective word(s). – Ben Mar 27 '17 at 15:51