how to get the value returned by the angle filter in the scope of the controller

advertisements

Is it possible to get the angular filter return value in controller scope. I need to pass the returned value of one filter to another filter. I have a filter defined as follows

     .filter('Filter', Filter)
function Filter($filter) {

    return FilterFn;

    function FilterFn(data, weight, waist) {
        var factor1 = weight * 1.082 + 94.42;
        var factor2 = waist * 4.15;
        var leanBodyMass = factor1 - factor2;
        var bodyFatWeight = weight - leanBodyMass;
        var bodyFatResults = bodyFatWeight * 100 / weight;
        // return Params
        if (bodyFatResults === "-Infinity") {
            // $filter('Filter2')(0);
            return 0;
        } else if (parseFloat(bodyFatResults) < 0) {
            //  $filter('Filter2')(2);
            return 2;
        } else {
            //  $filter('Filter2')(bodyFatResults.toFixed(1));
            return bodyFatResults.toFixed(1);
        }
    }
}

I need to get the returned value of this filter in controller scope.


Inject $filter inside your controller and use it like that:

.controller('Controller', function($filter) {
    var filtered = $filter('Filter2')(data, weight, waist);
});