trigger file upload event

别说谁变了你拦得住时间么 提交于 2019-12-24 02:37:09

问题


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) {


来源:https://stackoverflow.com/questions/30021335/trigger-file-upload-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!