Error: [ng: areq] The argument "module" is not a function, an object is received

I am trying to use an angular bootloader that loads it with npm and then browses all in one file. Details of the error can be seen here.

I can not understand the errors, because now I am still new to AngularJS. Here is my code

var angular = require('angular'); angular .module('jobApp', [require('angular-material'), require('ng-file-upload')]) .controller('MainCtrl', ['$rootScope', '$scope', '$mdToast', '$animate', '$http', '$timeout', '$q', '$log', 'Upload', function($rootScope, $scope, $mdToast, $animate, $http, $timeout, $q, $log, Upload) { 'use strict'; // Initialize the scope variables $scope.$watch('files', function () { $scope.upload($scope.files); }); $scope.upload = function (files) { if (files && files.length) { for (var i = 0; i < files.length; i++) { var file = files[i]; Upload.upload({ url: 'http://sr-recruit.herokuapp.com/resumes', fields: { 'name': $scope.name, 'email': $scope.email, 'about': $scope.about }, file: file }).progress(function (evt) { var progressPercentage = parseInt(100.0 * evt.loaded / evt.total); $scope.log = 'progress: ' + progressPercentage + '% ' + evt.config.file.name + '\n' + $scope.log; }).success(function (data, status, headers, config) { $scope.log = 'file ' + config.file.name + 'uploaded. Response: ' + JSON.stringify(data) + '\n' + $scope.log; $scope.$apply(); }); } } }; }]); 

UPDATE

Now I use Browserify-shim to correctly insert the Angular-file-upload file in Commonjs format. Thanks @ryan Johnson.

Here is the .json package

 { "browser": { "angular": "./node_modules/angular/angular.js", "ng-file-upload": "./node_modules/ng-file-upload/dist/ng-file-upload-all.js" }, "browserify-shim": { "angular": { "exports": "angular" }, "ng-file-upload": { "exports": "angular.module('ngFileUpload').name" } }, "browserify": { "transform": [ "browserify-shim" ] } } 

I'm still a mistake

 TypeError: Cannot read property '' of undefined 

I do not know why. FYI I am using Laravel-elixir built into the browser to complete the task.

+5
source share
1 answer

I noticed that you are using require('ng-file-upload') to enable the module. Although the ng-file-upload module is accessible via npm, the downloaded JS files are not in commonJS format.

In order for require('ng-file-upload') work in your example, the source file had to export the module as follows:

 module.exports = angular.module('ng-file-upload').name; 

Since this does not apply to the file that you include, you need to shim it to work with Browserify. Here is a good article on Correctly Shut Up AngularJS Applications Using Browserify .

+15
source

All Articles