Angular 4 - Convert numbers to words

My output {{total.number}}is in a numerical format, which is equal to 1. However, I want to convert this to one. I need this for 1-6 digits and the output will be shown as one- six.

How do I know this? I see only JS examples, but not the Angular method.

I got this example: https://jsfiddle.net/lesson8/5tt7d3e6/ , but I feel that it is too much to achieve what I am trying to do, that convert numbers from 1 to 6.

+4
source share
2 answers

First of all, you need to define an array with your elements and a value bindfor one variable, for example ng-model="number".

input, number (digest cicle ), , , index words .

<div id="word">{{words[number]}}</div>

function MyCtrl($scope) {
  $scope.number=1;
  $scope.words= ['','One','Two','Three','Four','Five','Six'];
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app>
  <div ng-controller="MyCtrl">
    <input type="text" ng-model="number" />
<div id="word">{{words[number]}}</div>
  </div>
</div>
Hide result
+2

:

$scope.numbers = {
            0: 'zero',
            1: 'one',
            2: 'two',
            3: 'three',
            4: 'four',
            5: 'five',
            6: 'six'
        }

{{this.numbers[total.number]}}

/

+2

Source: https://habr.com/ru/post/1687633/


All Articles