Valay
Valay

Reputation: 1999

$filter is not working

I've created a filter for the cell data of ui-grid. I want to apply my custom filter with built-in currency filter of angular. Please find below my code:

var HelperServices = angular.module("HelperServices",['Constants']);
HelperServices.filter('getPriceFormat',function(){
    return function(val, $filter){          
            if(val == 0)
                return;
            else
                return ($filter('currency')(val, "", 7));           
            }
});

I am getting error TypeError: undefined is not a function on return statement of else part.

How do I make built-in filter working inside custom filter ???

Upvotes: 0

Views: 151

Answers (2)

sfletche
sfletche

Reputation: 49774

You forgot to inject the $filter service into your filter

filter('getPriceFormat',function($filter){

or better yet with inline array annotation...

filter('getPriceFormat', ['$filter', function($filter){

Upvotes: 1

logee
logee

Reputation: 5077

You're injecting the $filter incorrectly, should be

HelperServices.filter('getPriceFormat',function($filter){
    return function(val){          
            if(val == 0)
                return;
            else
                return ($filter('currency')(val, "", 7));           
            }
});

Upvotes: 2

Related Questions