Angular filter for currency to allow typing negative numbers
<p>I have a directive that filters currency by adding a decimal point as the user types.</p>

<p>My problem is that it will not allow negatives. It would be nice to allow a user to type a '-' sign and have it always appear at the beginning of the number, or type a '+' and have it disappear.</p>

<p>Needs:</p>

<ol>
<li>Format decimal field as user types</li>
<li>Field must be a number</li>
<li>Must allow negatives <code>-</code></li>
<li>Allow 0.00 as a number input</li>
</ol>

<p><a href="http://plnkr.co/edit/qlZrc7dnZEUWzoNGyaF6?p=preview" rel="nofollow">Check out my  Plunker here</a> . It has <code>input = number</code> but does not allow negative numbers:</p>

<pre><code>app.directive('format', ['$filter', function ($filter) {
    return {
        require: 'ngModel', //there must be ng-model in the html
        link: function (scope, elem, attr, ctrl) {
            if (!ctrl) return;

            ctrl.$parsers.unshift(function (viewValue, modelValue) {
                var plainNumber = viewValue.replace(/[^-+0-9]/g,'');

                // use angular internal 'number' filter
                plainNumber = $filter('number')(plainNumber / 100, 2).replace(/,/g, '');

                // update the $viewValue
                ctrl.$setViewValue(plainNumber);

                // reflect on the DOM element
                ctrl.$render();

                // return the modified value to next parser
                return plainNumber;
            });
        }
    };
}]);
</code></pre>