无法将上传的文件从HTML发布到AngularJS

时间:2016-08-19 13:49:02

标签: javascript html angularjs

我想使用AngularJS上传文件,但我无法在ng-controller中获取该文件。它显示为未定义。下面是HTML和AngualrJS代码。请帮忙。



<form id="upload" enctype="multipart/form-data" method="post" data-ng-submit="uploadFile()">
  <p>
    <div class="form-group">
      <input type="file" file-model="myFile" />
    </div>
  </p>
  <button type="submit">Upload</button>
</form>
&#13;
&#13;
&#13;

&#13;
&#13;
'use strict';

var UploadFileController = angularApp
  .controller(
    'UploadFileController',
    function UploadFileController($scope, $rootScope,
      UserDataService, $http, $location, $window,
      UtilService, CommonDataService, ControllerService) {

      $scope.uploadFile = function() {
        var nameFile = $scope.myFile;
        console.log("Uploaded file====>>> ", nameFile);

      };

      $scope.init = function() {
        console.log("Upload Controller InitApp");
      }

      angular.element(document).ready(function() {
        $scope.init();

      });


    });
&#13;
&#13;
&#13;

0 个答案:

没有答案