Truncate Filter for AngularJS v1

This is a custom filter to truncate text. It gives you the possibility to specify the length and the end string of the text.

HTML

<div ng-app="myApp">
     <h2>TextOrNumber Filter Example</h2>

    <div>
        <input type="text" ng-model="myText" placeholder="add your text here" />
    </div>
    <div>
         <h3>Output:</h3>

        <p>{{myText|textOrNumber:4}}</p>
    </div>
</div>

JavaScript

// add the filter to your application module
angular.module('myApp', ['filters']);


angular.module('filters', []).
filter('textOrNumber', function ($filter) {
    return function (input, fractionSize) {
        if (isNaN(input)) {
            return input;
        } else {
            return $filter('number')(input, fractionSize);
        };
    };
});