本文介绍了触发文件上传事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

当我选择要上传的文件时,我无法触发名为onFileSelect的文件上传相关事件。这是我的代码。

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>

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....
    }
}]);

在我的Index.cshtml页面中... mydata正确呈现为预期状态,因此我的angularjs接线正常工作

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>


推荐答案

我认为您这一行有依赖注入错误:

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

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

应为:

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

这篇关于触发文件上传事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 12:07