Tôi cố gắng sử dụng angular uploader để tải xuống bằng npm và sau đó duyệt tất cả trong một tệp. Bạn có thể xem chi tiết lỗi hereLỗi: [ng: areq] Đối số 'mô-đun' không phải là một hàm, có đối tượng
Tôi không thể hiểu được lỗi vì hiện tại tôi vẫn còn mới với AngularJS. Đây là mã của tôi
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();
});
}
}
};
}]);
CẬP NHẬT
Bây giờ đang sử dụng Browserify-shim để kèm theo đúng góc-file-upload ở định dạng Commonjs. Cảm ơn @ryan Johnson.
Đây là package.json
{
"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"
]
}
}
tôi vẫn lỗi
TypeError: Cannot read property '' of undefined
Không chắc lý do tại sao. FYI Tôi sử dụng Laravel-elixir được xây dựng trong trình duyệt để chạy tác vụ.
Mảng * require * (2 arg đến 'mô-đun') phải là một chuỗi các chuỗi – Phil
ý của bạn là gì? '.module ('jobApp', [require ('angular-material'), yêu cầu ('ng-file-upload')])'? – Muhaimin
Nó phải là '.module ('jobApp', ['ngMaterial', 'ngFileUpload'])'. Tôi không chắc chắn những gì các phiên bản mô-đun nút của những người xuất khẩu nhưng tôi đặt cược nó không phải là một chuỗi (chỉ cần kiểm tra ng-file-upload và nó không có xuất khẩu mô-đun) – Phil