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.

by daver182

HTML

<div ng-app="myApp">
     <h2>Custom Search Filter Example:</h2>

    <div>
        <input type="text" ng-model="searchStr" placeholder="Enter number" />
    </div>
    <div>
         <h3>Output:</h3>

        <p>{{"10"|search:searchStr}}</p>
    </div>
</div>

JavaScript

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


angular.module('customFilters', []).
    filter('search', function () {
        return function (input, searchStr) {
            if (input == searchStr) {
                return input;
            } else {
                return undefined;
            }
        };
    });