react2angular
The easiest way to embed React components in Angular 1 apps! (opposite of angular2react)
Installation
# Using Yarn: yarn add react2angular react react-dom prop-types # Or, using NPM: npm install react2angular react react-dom prop-types --save
Usage
1. Create a React component
{ return <div> <p>FooBar: thispropsfooBar</p> <p>Baz: thispropsbaz</p> </div> }
2. Expose it to Angular
angular
Note: If you defined propTypes
on your component, they will be used to compute component's bindings, and you can omit the 2nd argument:
...
If propTypes
are defined and you passed in a 2nd argument, the argument will override propTypes
.
3. Use it in your Angular 1 code
Dependency Injection
It's easy to pass services/constants/etc. to your React component: just pass them in as the 3rd argument, and they will be available in your component's Props. For example:
state = data: '' { thisprops$http } { return <div> thispropsFOO thisstatedata </div> } angular
Note: If you have an injection that matches the name of a prop, then the value will be resolved with the injection, not the prop.
Tests
npm test
License
Apache2