# @flowjs/ng-flow 中文文档

规范地址：https://npmcn.com/package/%40flowjs/ng-flow/

版本：2\.7\.8
npm 元数据更新时间：2022-06-12T18:01:50.892Z
中文译文更新时间：2026-11-15T00:32:54.857Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40flowjs/ng-flow
原文对照：https://npmcn.com/package/%40flowjs/ng-flow/?lang=original
项目主页：https://github.com/flowjs/ng-flow#readme
源码仓库：https://github.com/flowjs/ng-flow

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：147 kB，37 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- 运行依赖：0 个
- 首次发布：2016-01-25T16:25:52.289Z
- 最新版本发布：2018-03-17T22:22:29.624Z
- 近 30 天下载量：14840（2026-10-15 至 2026-11-13，npm 官方下载统计）
- 已发布版本数：4（近 12 个月 0 个）

## 中文简介

Flow.js html5 文件上传扩展名于 angular.js 框架

## 安装

```sh
npm install @flowjs/ng-flow
```

也可以使用：`pnpm add @flowjs/ng-flow`、`yarn add @flowjs/ng-flow`、`bun add @flowjs/ng-flow`

## README

# 纳克流量 [![Build Status](https://travis-ci.org/flowjs/ng-flow.svg)](https://travis-ci.org/flowjs/ng-flow) [![Test Coverage](https://codeclimate.com/github/flowjs/ng-flow/badges/coverage.svg)](https://codeclimate.com/github/flowjs/ng-flow/coverage)

[![Saucelabs Test Status](https://saucelabs.com/browser-matrix/ng-flow.svg)](https://saucelabs.com/u/ng-flow)

纳克流是一个 [流动.js](https://github.com/flowjs/flow.js) 对angular.js框架的扩展,不需要第三党JS依赖性!

发音: [http://flowjs.github.io/ng-flow/ (英语)](http://flowjs.github.io/ng-flow/)

# 我怎么装?

1.  获取图书馆:

**直接下载** 从 [https://github.com/flowjs/ng-flow/release (英语)](https://github.com/flowjs/ng-flow/releases) 它包含开发与精密化生产文件 `dist/` 目录, 它们也与核心流相配合.js库.

**使用鲍尔**

```
    bower install ng-flow#~2
```

**Git 克隆语**

```
    git clone https://github.com/flowjs/ng-flow
```

**使用耀曼语**

```
    bower install "ng-flow#~2" --save
    grunt bower-install
```

2.  将模块添加到您的应用程序中作为依赖 :
    
    ```
     angular.module('app', ['flow'])
    ```
    
3.  在您的工程中包含文件
    

```html
<!-- concatenated flow.js + ng-flow libraries -->
<script src="ng-flow/dist/ng-flow-standalone.min.js"></script>
<!-- or include the files separately -->
<script src="flow.js/dist/flow.min.js"></script>
<script src="ng-flow/dist/ng-flow.min.js"></script>
```

# 我该怎么用呢?

首先,你要用 Flow.js 来包装地方

```html
<div flow-init>
    ... other flow directives goes here ...
</div>
```

此指令将在当前范围中添加 $flow 变量 . 指令也可以嵌入,因为 `$flow` 变量将被覆盖. `$flow` 实例 [流动](https://github.com/flowjs/flow.js#flow)。 。 。 .

其次, 您需要指定一些上传按钮 :

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

第一个按钮用于正常上传,第二个按钮用于目录上传. 注:避免使用 `<a>` 财务报告和审定财务报表 `<button>` 标签作为文件上传按钮,使用 `<span>` 换句话说.

现在您需要显示上传的文件,只需要循环文件阵列. 文件数组附在命名的流程对象上 `$flow`。 。 。 .

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

文件为实例 [流程文件](https://github.com/flowjs/flow.js#flowfile)。 。 。 .

### 快速设置

`````html
<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>
```

Need more examples?
============
Clone this repository and go to "ng-flow/samples/basic/index.html".
Single image upload "ng-flow/samples/image/index.html".


How can I drop files?
============

Use `flow-drop` directive:
````html
<div class="alert" flow-drop>
    Drag And Drop your file here
</div>
`````

说明:在大多数情况下 `flow-drop` 必须与 `flow-prevent-drop` 指令 `body` 元素,因为它防止文件被载入浏览器.

### 防止在文档上丢弃文件

使用 `flow-prevent-drop` 指令 `body` 元素 :

```html
<body flow-prevent-drop>

</body>
```

### 丢弃文件时如何添加一些样式 ?

使用 `flow-drag-enter` 指令 :

```html
<div flow-drag-enter="style={border:'4px solid green'}" flow-drag-leave="style={}"
     ng-style="style">
</div>
```

说明: `flow-drag-leave` 属性不能单独使用,它是 `flow-drag-enter` 指令.

### 如何动态禁用投放区域 ?

```html
<div class="alert" flow-drop flow-drop-enabled="config.enabled">
    Drag And Drop your file here
</div>
```

见实例 `samples/dataurl/`。 。 。 .

# 如何预览上传的图像 ?

使用流程-img指令 :

```html
<img flow-img="$flow.files[0]" />
```

一旦添加文件, 图像将自动更新 。 无需开始上传 .

# 我怎么才能为流动设定选项?.js?

使用配置 :

```javascript
var app = angular.module('app', ['flow'])
.config(['flowFactoryProvider', function (flowFactoryProvider) {
    flowFactoryProvider.defaults = {
        target: '/upload',
        permanentErrors:[404, 500, 501]
    };
    // You can also set default events:
    flowFactoryProvider.on('catchAll', function (event) {
      ...
    });
    // Can be used with different implementations of Flow.js
    // flowFactoryProvider.factory = fustyFlowFactory;
}]);
```

也可以在"flow-init"指令上配置:

```html
<div flow-init="{target:'/uploader'}">

</div>
```

# 我怎样才能赶上事件?

事件列于内部 `flow-init` 指令 :

```html
<div flow-init
        flow-file-success="someHandlerMethod( $file, $message, $flow )"
        flow-file-progress="someHandlerMethod( $file, $flow )"
        flow-file-added="someHandlerMethod( $file, $event, $flow )"
        flow-files-added="someHandlerMethod( $files, $event, $flow )"
        flow-files-submitted="someHandlerMethod( $files, $event, $flow )"
        flow-file-retry="someHandlerMethod( $file, $flow )"
        flow-file-error="someHandlerMethod( $file, $message, $flow )"
        flow-error="someHandlerMethod( $file, $message, $flow )"
        flow-complete=" ... "
        flow-upload-started=" ... "
        flow-progress=" ... "
      >
      <div flow-file-progress=" ... events can be also assigned inside flow-init ... "></div>

</div>
```

### 我怎么能在控制器里抓住一个事件?

如果控制器与 `flow-init` 指令或儿童范围, 然后我们就可以赶上事件 `$on`。事件前缀为 `flow::`。 。 。 .

```javascript
$scope.$on('flow::fileAdded', function (event, $flow, flowFile) {
  event.preventDefault();//prevent file from uploading
});
```

第二个论点总是 `flow` 实例,然后遵循事件特定参数.

# 如何分配流到母范围?

使用 `flow-name` 属性并设定为范围中的任何变量.

```html
<div flow-init flow-name="obj.flow">
    ... Flow is set to obj.flow  ...
    I have uploaded files: #{{obj.flow.files.length}}
</div>
```

```javascript
$scope.obj = {}; // variable "obj" must be initialized on the scope
```

# 如何以已有的流对象初始化流?

使用 `flow-object` 属性,并设置在范围上的现有流动对象.

```html
<div flow-init flow-object="existingFlowObject">
    ... Flow is initialized with existingFlowObject, no new Flow object  is created ...
    There are already {{ existingFLowObject.files.length }} files uploaded,
    which is equal to {{ $flow.files.length }}.
</div>
```

# 我怎么支持更老的浏览器?

转到 [https://github.com/flowjs/fusty-flow.js (中文(简体) )](https://github.com/flowjs/fusty-flow.js) 并在配置中添加:

```javascript
var app = angular.module('app', ['flow'])
.config(['flowFactoryProvider', function (flowFactoryProvider) {
    flowFactoryProvider.factory = fustyFlowFactory;
}]);
```

# 捐款

为确保源代码的一致性,请在工作时铭记这些规则:

-   所有特性或bug修正必须经过一个或多个规格的测试.
    
-   除下文所列的例外情况外,我们遵循载于第12条的规则 [Google 的 JavaScript 样式指南](http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml)数字 :
    
    -   以100个字符包起所有代码 .
        
    -   而不是复杂的继承等级, 我们更喜欢简单的对象。 我们使用原型 只有在绝对必要时才能继承遗产.

## 常见问题

### @flowjs/ng-flow 是什么？

Flow\.js html5 文件上传扩展名于 angular\.js 框架

### 如何安装 @flowjs/ng-flow？

在项目目录运行 npm install @flowjs/ng-flow，或使用 pnpm add / yarn add / bun add。

### @flowjs/ng-flow 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/flowjs\_\_ng-flow 是否存在。

### @flowjs/ng-flow 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @flowjs/ng-flow 可以商用吗？

@flowjs/ng-flow 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @flowjs/ng-flow 的下载量有多少？

根据 npm 官方下载统计，@flowjs/ng-flow 在 2026/10/15 – 2026/11/13 这 30 天内被下载 14,840 次，日均约 495 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @flowjs/ng-flow 还在维护吗？

最新版本 2\.7\.8 发布于 2018/03/18（8 年前）；至今共发布 4 个版本，其中过去 12 个月发布了 0 个；首次发布于 2016/01/26。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

