在 Angular gridOptions 中调用另一个函数

Calling another function within Angular gridOptions

我在我的控制器中创建了一个 dateTime 函数,如下所示:

    $scope.getDatetime = function() {
        return (new Date()).toLocaleFormat("%A, %B %e, %Y") + "name.csv" ;
    };

我正在使用 gridOptions 如下

    $scope.gridOptions = {
        exporterCsvFilename: 'getDatetime()',
        exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
        columnDefs: [
            { field: 'Field1' },
            { field: 'Field1' }
        ]
    };

使用上述语法,文件正在下载,名称为 getDatetime().csv,而不是显示实际日期

不要给单引号,如果你给单引号它会被认为是一个字符串

$scope.gridOptions = {
            exporterCsvFilename:$scope.getDatetime(),//call the function
            exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
            columnDefs: [
                { field: 'Field1' },
                { field: 'Field1' }
            ]
        };