2

I can't seem to get the Alasql to become defined, i have installed it via node and I'm fairly certain that it is installed proplery however whenever i load my front end. i'm not 100% sure where it's going wrong, any help would be greatly appreciated!

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]);
        };
GingerFish
  • 457
  • 3
  • 11
  • 26

1 Answers1

1

1 - From their own angularjs readme:

Please include the file normally and not via requireJS. Please include alasql before requireJS to avoid issue of "Mismatched anonymous define() module". This issue is with requireJS.

2 - I had "alasql is undefined" when using grunt to build my project. So I had to include alasql in my jshint file under "globals" section:

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

PS: I recommend you exporting to ".xlsx" instead of ".xls". Microsoft is now refusing to open those files.

Rick Wolff
  • 769
  • 11
  • 25