2

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

<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 接线工作正常。

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

1 回答 1

0

我认为你在这一行有一个依赖注入错误:

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

应该:

app.controller('fileCtrl', ['$scope', '$http', '$timeout', '$upload', function ($scope, $http, $timeout, $upload) {
于 2015-05-04T01:42:15.900 回答