Function function_name($column) must be instance of $q.defer()

344 views Asked by At

I trying to display a table with dynamic data.Data is displaying fine.But i am not able to apply custom filter. The following error is seen

Function ConstraintValues($column) must be instance of $q.defer()

html

<div ng-show="showfindResults">
    <table ng-table="tableParams" show-filter="true" class="table">
        <tr ng-repeat="value in $data">
            <td data-title="'ConstraintValue'"
                filter="{ 'ConstraintValue': 'select'        }"
                filter-data="ConstraintValues($column)">{{value.ConstraintValue}}
            </td>
            <td data-title="'comRef'"><a
                href="{{comRefURL}}{{value.comRef}}{{langCode}}">{{value.comRef}}</a>
            </td>
            <td data-title="'coordinationValue'">
                {{value.coordinationValue}}</td>
        </tr>
    </table>
</div>

controller

var app=angular.module('app.controllers'['ngRoute','ui.router','ui.bootstrap','ngTable']);

app.controller('findController', ['$scope','findService','$filter','$q','ngTableParams','$http','UPSTREAM_URL',function($scope,findService,$filter, $q, ngTableParams,$http,UPSTREAM_URL) {
    $scope.showfindResults = false;
    $scope.showMsg = false;

    $scope.find = function(){
        if ($scope.findForm.$valid){
            $scope.loadingShow=true;
            $scope.showMsg = false;
            $scope.isDisableSubmit=true;
            var coordinationType=$scope.selectedCd;
            var comRef=$scope.selectedCommRef;
            var position=$scope.selectedPosition;
            var comRefModel=$scope.comRefModel;
            var queryParameter = "?coordinationType="+coordinationType+"&comRef="+comRef+"&position="+position+"";
            $scope.comRefURL=UPSTREAM_URL+"?product=";
            $scope.langCode="&code=en-US";

            findService.find(queryParameter,function (results) {
                    if(results.statusCode==200){
                        var data =results.message;
                        $scope.showMsg = false;
                        $scope.status=1;
                        $scope.loadingShow=false;
                        $scope.isDisableSubmit=false;
                        $scope.showfindResults = true;

                        $scope.tableParams = new ngTableParams({
                            page: 1,
                            count: 10,
                        },
                        {
                            total: data.length,
                            getData: function($defer, params) {
                                alert("in get data");
                                var orderedData = params.sorting ?$filter('orderBy')(data, params.orderBy()) :data;
                                orderedData = params.filter ?$filter('filter')(orderedData, params.filter()) :orderedData;
                                $scope.values = orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count());
                                params.total(orderedData.length);
                                $defer.resolve($scope.values);
                                }
                            });

                        var inArray = Array.prototype.indexOf ?
                                function (val, arr) {
                                    return arr.indexOf(val)
                                } :
                                function (val, arr) {
                                    var i = arr.length;
                                    while (i--) {
                                        if (arr[i] === val) return i;
                                    }
                                    return -1;
                                }
                        $scope.coordinationValues = function(column) {
                            alert("in 274");
                            var def = $q.defer(),
                                arr = [],
                                coordinationValues = [];
                            angular.forEach(data, function(item){
                                if (inArray(item.coordinationValue, arr) === -1) {
                                    arr.push(item.coordinationValue);
                                    coordinationValues.push({
                                        'id': item.coordinationValue,
                                        'title': item.coordinationValue
                                    });
                                }
                            });
                            def.resolve(coordinationValues);
                            return def;
                        };

                        $scope.ConstraintValues = function(column) {
                            alert("in function");
                            var def = $q.defer(),
                                arr = [],
                                ConstraintValues = [];
                            angular.forEach(data, function(item){
                                if (inArray(item.ConstraintValue, arr) === -1) {
                                    arr.push(item.ConstraintValue);
                                    ConstraintValues.push({
                                        'id': item.ConstraintValue,
                                        'title': item.ConstraintValue
                                    });
                                }
                            });
                            def.resolve(ConstraintValues);
                            return def;
                        };

                        $scope.comRefs = function(column) {
                            var def = $q.defer(),
                                arr = [],
                                comRefs = [];
                            angular.forEach(data, function(item){
                                if (inArray(item.comRef, arr) === -1) {
                                    arr.push(item.comRef);
                                    comRefs.push({
                                        'id': item.comRef,
                                        'title': item.comRef
                                    });
                                }
                            });
                            def.resolve(comRefs);
                            return def;
                        };
                    }
                },
                function(error){
                    console.log('Error while getting response from the REST call');
                    $scope.successMessage = error.message;
                    $scope.status=0;
                    $scope.loadingShow=false;
                    $scope.isDisableSubmit=false;
                    $scope.showMsg = true;
                    $scope.showfindResults = false;
                });


        }
    }
}]);
0

There are 0 answers