# @bitrise/react2angular 中文文档

规范地址：https://npmcn.com/package/%40bitrise/react2angular/

版本：5\.0\.0
npm 元数据更新时间：2026-01-06T10:32:16.618Z
中文译文更新时间：2026-11-08T04:45:42.924Z
软件包许可：Apache-2\.0

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

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

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

- 包体积（解压后）：10.5 kB，6 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：4 个
- peer 依赖：react \>=18，react-dom \>=18，@types/react \>=18，@types/angular \>=1\.5，@types/react-dom \>=18
- 首次发布：2022-07-19T11:04:59.112Z
- 最新版本发布：2022-07-19T11:04:59.314Z
- 近 30 天下载量：4198（2026-10-08 至 2026-11-06，npm 官方下载统计）
- 已发布版本数：1（近 12 个月 0 个）

## 中文简介

在 Angular 1 apps 中嵌入 React 组件最简单的方式 !

## 安装

```sh
npm install @bitrise/react2angular
```

也可以使用：`pnpm add @bitrise/react2angular`、`yarn add @bitrise/react2angular`、`bun add @bitrise/react2angular`

## README

![React to Angular: The easiest way to use React components in Angular 1](https://raw.githubusercontent.com/coatue-oss/react2angular/master/logo.png)

# 反应2角 [![Build Status](https://img.shields.io/circleci/project/coatue-oss/react2angular.svg?branch=master&style=flat-square)](https://circleci.com/gh/coatue-oss/react2angular) [![NPM](https://img.shields.io/npm/v/react2angular.svg?style=flat-square)](https://www.npmjs.com/package/react2angular) [![Apache2](https://img.shields.io/npm/l/react2angular.svg?style=flat-square)](https://opensource.org/licenses/Apache2)

> 在 Angular 1 apps 中嵌入 React 组件最简单的方式 ! (反对: [角2反应](https://github.com/coatue-oss/angular2react)(中文(简体) )

## 安装

```sh
# Using Yarn:
yarn add react2angular react react-dom prop-types

# Or, using NPM:
npm install react2angular react react-dom prop-types --save
```

## 使用量

### 1\. 创建反应组件

```js
import { Component } from 'react'

class MyComponent extends Component {
  render() {
    return <div>
      <p>FooBar: {this.props.fooBar}</p>
      <p>Baz: {this.props.baz}</p>
    </div>
  }
}
```

### 2\. 将其展示给角星

```js
import { react2angular } from 'react2angular'

angular
  .module('myModule', [])
  .component('myComponent', react2angular(MyComponent, ['fooBar', 'baz']))
```

注:如果定义 [`propTypes`](https://facebook.github.io/react/docs/typechecking-with-proptypes.html) 在您的组件上,它们将被用于计算组件的绑定值,您可以省略第二个参数:

```js
...
  .component('myComponent', react2angular(MyComponent))
```

若为 `propTypes` 被定义, 您在第二个参数中通过, 参数将覆盖 `propTypes`。 。 。 .

### 3\. 在您的角 1 代码中使用

```html
<my-component
  foo-bar="3"
  baz="'baz'"
></my-component>
```

注:所有回放道具被转换为AngularJS单向绑定. 如果您正在将函数传递到您的 React 组件中, 它们需要被传递为函数 ref, 而不是一个可撤回的表达式 。 保留现有的AngularJS风格的表达方式将随着函数在每个消化回路上重新评价而产生无限回路.

## 依赖性注射

很容易通过服务/constants/etc.到您的 React 组件:只是通过它们作为第3个参数,它们将会在您的组件的Propals中可用. 例如:

```js
import { Component } from 'react'
import { react2angular } from 'react2angular'

class MyComponent extends Component {
  state = {
    data: ''
  }
  componentDidMount() {
    this.props.$http.get('/path').then(res =>
      this.setState({ data: res.data })
    )
  }
  render() {
    return <div>
      { this.props.FOO }
      { this.state.data }
    </div>
  }
}

angular
  .module('myModule', [])
  .constant('FOO', 'FOO!')
  .component('myComponent', react2angular(MyComponent, [], ['$http', 'FOO']))
```

注意:如果有与道具名称相匹配的注射,则该值会用道具而不是道具来解决.

## 测试

```sh
npm test
```

## 许可证

阿帕奇2号

## 常见问题

### @bitrise/react2angular 是什么？

在 Angular 1 apps 中嵌入 React 组件最简单的方式 \!

### 如何安装 @bitrise/react2angular？

在项目目录运行 npm install @bitrise/react2angular，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：react（\>=18）、react-dom（\>=18）、@types/react（\>=18）、@types/angular（\>=1\.5）、@types/react-dom（\>=18）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @bitrise/react2angular 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @bitrise/react2angular 支持 ESM 还是 CommonJS？

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

### @bitrise/react2angular 可以商用吗？

@bitrise/react2angular 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @bitrise/react2angular 的下载量有多少？

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

### @bitrise/react2angular 还在维护吗？

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

