我似乎无法定义Alasql,我已经通过node安装了它,并且可以肯定地说,无论何时加载前端,都可以正确安装Alasql。我不是100%知道哪里出了问题,任何帮助将不胜感激!

require is not defined at Scope.$scope.exportData





 $scope.exportData = function () {

                var mystyle = {
                sheetid: 'Account sheet',
                headers: true,
                caption: {
                    title:'My Big Table',
                },
                style:'background:#00FF00',
                column: {
                    style:'font-size:30px'
                },
                columns: [
                    {columnid:'Date'},
                    {columnid:'Description'},
                    {columnid:'Due'},
                    {columnid:'Charged £'},
                    {columnid:'Received £'},
                    {columnid:'Balanced £'},
                    {
                        columnid:'name',
                        title: 'Number of letters in name',
                        width: '300px',
                        cell: {
                            value: function(value){return value.length}
                        }
                    },
                ],
                row: {
                    style: function(sheet,row,rowidx){
                        return 'background:'+(rowidx%2?'red':'yellow');
                    }
                },
                rows: {
                },
                cells: {
                    2:{
                        2:{

                        }
                    }
                }
            };

        $scope.exportData = function () {
            var alasql = require('alasql');
            alasql('SELECT * INTO XLS("report.xls",?) FROM ?',[mystyle,records]);
        };

最佳答案

1-来自自己的angularjs readme


  请正常包含文件,而不是通过requireJS包含文件。请在requireJS之前包含alasql,以避免出现“不匹配的匿名define()模块”问题。这个问题与requireJS有关。


2-使用grunt构建项目时,出现“ alasql未定义”的问题。因此,我必须在“ globals”部分的jshint文件中包含alasql:

{
  .
  .
  .
  "globals": {
    "angular": false,
    "confirm": false,
    "console": false,
    "alert": false,
    "alasql": false
  }
}


PS:我建议您导出到“ .xlsx”而不是“ .xls”。微软现在是refusing to open those files

10-06 07:45