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

问题描述

我目前使用的NG-流程来执行文件上传。看来,选择文件的默认操作是立即上传。我想,这样的文件被选中,只有上载按钮点击覆盖。也许我误读了文件,但迄今为止我有以下几点:

I am currently using ng-flow to perform a file upload. It appears that the default action of selecting a file is to upload immediately. I'd like to override this so that files are selected and only uploaded on button click. Perhaps I am misreading the documentation, but thus far I have the following:

<div flow-init="{target: '/upload'}"
     flow-files-submitted="$flow.upload()"
     flow-file-success="$file.msg = $message">

  <input type="file" flow-btn/>
  Input OR Other element as upload button
  <span class="btn" flow-btn>Upload File</span>

  <table>
    <tr ng-repeat="file in $flow.files">
        <td>{{$index+1}}</td>
        <td>{{file.name}}</td>
        <td>{{file.msg}}</td>
    </tr>
  </table>
</div>

这似乎是工作,我可以看到网络请求外出。我所在上传文件,并试图遵循建议的答复然而 $流程是未定义在各自的功能。

This appears to work and I can see the network request going out. I located flow.js upload file on click and attempted to follow the suggested answer, however $flow was undefined in the respective function.

那么,一个人如何以编程方式使用NG-流上传文件?

So, how does one programmatically upload files using ng-flow?

推荐答案

首先,流文件提交当用户选择一个文件(误导名)事件被触发。所以,当你指定 $ flow.upload()来,你让它选择文件后立即上传

At first, flow-files-submitted event is triggered when user pick a file (misleading name). So when you assign $flow.upload() to it, you make it uploading immediately after file selection.

第二件事是让$流对象在控制器中。有两种方法来我的脑海:

Second thing is to get $flow object in your controller. Two ways comes to my mind:

一个。为指导说,你必须使用流名称属性:

A. As instruction say, you have to use flow-name attribute:

<div flow-init flow-name="obj.flow">

然后,你必须参考你的 $流程 $ scope.obj.flow 属性,你可以使用 $ scope.obj.flow.upload()在你的控制器的任何位置方法。

Then you have reference to $flow in yours $scope.obj.flow property and you can use $scope.obj.flow.upload() method anywhere in your controller.

乙。把你的上传流指令块内的按钮(如元素的后代与流的init 属性),并使用 $流程 NG-点击指令范围作为参数的属性,例如:

B. Put your "Upload" button inside flow directive block (as a descendant of element with flow-init attribute) and use $flow property of directive scope as a parameter in ng-click, for example:

<button type="button" ng-click="myUploadMedhot($flow)">Upload</button>

和里面的 myUploadMethod(参数)就叫 param.upload()

这篇关于NG-流上传编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 23:14