使用输入类型=文件选择文件并使用ng-repeat显示路径后触发函数

Trigger a function after choosing a file using input type=file and display path using ng-repeat

本文关键字:文件 路径 函数 显示 输入 类型 选择 ng-repeat      更新时间:2023-09-26
  <input type="file" id="file" name="file" ng-show="attachFile" />
  <button type="button" ng-model="attach" ng-click="add()">Attach</button>
  <div class="panel panel-default" ng-show="displayAttachments">
    <div class="panel-heading">
      <h3 class="panel-title">Attachments</h3>
    </div>
    <div class="panel-body">
      <ul class="list-group">
        <li class="list-group-item">C:'fakepath'angularjs_tutorial.pdf</li>
        <li class="list-group-item">display file path using ng-repeat in this panel</li>
      </ul>
    </div>
  </div>

我有一个名为 attach 的按钮,它调用我的控制器中编写的 add() 函数,该函数启用类型文件的输入。功能是

  • 单击添加时显示选择文件按钮(输入类型=文件)
  • 选择"文件"
  • 后,此"选择文件"必须消失并显示"附件"字段
  • 文件的路径必须出现在附件字段的li标签中,我认为可以使用ng-repeat来完成
  • 我必须能够通过上述文件上传另一个文件,并且此新文件的路径必须出现在已选择的路径下方文件。

我的控制器有此代码

$scope.attachFile = false;
$scope.displayAttachements = false;
$scope.add = function() {
  $scope.attachFile = true;
}

检查此解决方案 我认为这会有所帮助,因为文件类型输入属性没有绑定