Circular dependency Error when using a custom filter and filterOptions

first I got a Filter "fromMSDate" that I use to transform json dates not normal dates, if this filter is place then refresh my input that is bound to filterOptions.filterText I get 'Circular dependency' and 'Unknown provider: fromMSDate | dateFilterProvider <- fromMSDate '

//Module


var mainApp = angular.module('mainApp', ['ngGrid']);

//Controller


    mainApp.controller('MandateListController', function MandateListController($scope) {
        $scope.filterOptions = { filterText: '' };
        $scope.mandates = data;
        $scope.gridOptions = {
            data: "mandates",
            filterOptions: $scope.filterOptions,
            sortInfo: { fields: ['ExpectedDate', 'ProjectName'], directions: ['desc', 'asc'], columns: ['ExpectedDate', 'ProjectName'] },
            columnDefs: [
                { field: 'ProjectName', displayName: 'Project Name', width: '30%', cellClass: 'text-center' },
                { field: 'Amount', displayName: 'Size', cellFilter: 'number:2', cellClass: 'text-right' },
                { field: 'RatingId', displayName: 'Rating', cellClass: 'text-center' },
                { field: 'CurrencyId', displayName: 'Currency', cellClass: 'text-center' },
                { field: 'MaturityId', displayName: 'Maturity', cellClass: 'text-center' },
                { field: 'EstimatedPl', displayName: 'Estimated P/L', cellFilter: 'number:2', cellClass: 'text-right' },
                { field: 'ExpectedDate', displayName: 'Expected Date', cellClass: 'text-center', cellFilter: "fromMSDate | date:'mediumDate'" }
                    ]
           };
    });

//filter


    mainApp.filter("fromMSDate", [function () {
         var result = function(date, formatstring) {
              if (formatstring === null || formatstring === undefined) {
                  formatstring = "DD MMM YYYY";
              }

              return moment(date).format(formatstring);
         };

        return result;    
    }]);


If I correctly understand you somehow include into the HTML page the contents of $scope.gridOptions.columnDefs[].cellFilter . In the last columnDef you have the following filter:

fromMSDate | date:'mediumDate'

I think you expect that date will be passed as the first argument and 'mediumDate' as the second, but filters in angular.js has another syntax and you need to write this way:

date | fromMSDate:'mediumDate'

Filters are added to the expression with | character and get the prior expression as the first argument. Other arguments could be specified after : .

So in your example angular.js recognizes 'date' as filter name and fails to find DateFilter or DateFilterProvider for it.

链接地址: http://www.djcxy.com/p/77848.html

上一篇: 路由器警告:试图加载角度不止一次

下一篇: 循环依赖关系使用自定义过滤器和filterOptions时出错