trigger file upload event

2019-07-21 15:58发布

问题:

I am unable to trigger file upload related event called onFileSelect when I select the file to upload. Here is my code.

<head>
    <script src="~/Scripts/angular.min.js"></script>
    <script src="~/Scripts/angular-file-upload.min.js"></script>

    <script src="~/App/Main.js"></script>
....
</head>
<body data-ng-app="app">

....

</body>

Inside Main.js

var app = angular.module('app', ['angularFileUpload']);

app.controller('fileCtrl', ['$scope', function ($scope, $http, $timeout, $upload) {
    $scope.mydata = 4 * 11; //*** I am able to hit the break point here

    $scope.onFileSelect = function ($files) {
        var j = 33; /*** this is not getting triggered....
    }
}]);

Inside my Index.cshtml page... mydata gets rendered as expected correctly so my angularjs wiring is working correctly.

<div data-ng-controller="fileCtrl">
    <h2>{{mydata}}</h2>
    <input type="file" ng-file-select="onFileSelect($files)" multiple>
</div>

回答1:

I think you have a Dependency Injection error on this line:

app.controller('fileCtrl', ['$scope', function ($scope, $http, $timeout, $upload) {

should be:

app.controller('fileCtrl', ['$scope', '$http', '$timeout', '$upload', function ($scope, $http, $timeout, $upload) {