The easiest way to embed React components in Angular 1 apps! (opposite of angular2react)
npm install react2angular react react-dom prop-types --save
import { Component } from 'react'
class MyComponent extends Component {
render() {
return <div>
<p>FooBar: {this.props.fooBar}</p>
<p>Baz: {this.props.baz}</p>
</div>
}
}
import { react2angular } from 'react2angular'
angular
.module('myModule', [])
.component('myComponent', react2angular(MyComponent, ['fooBar', 'baz']))
Note: If you defined propTypes
on your component, they will be used to compute component's bindings, and you can omit the 2nd argument:
...
.component('myComponent', react2angular(MyComponent))
If propTypes
are defined and you passed in a 2nd argument, the argument will override propTypes
.
<my-component
foo-bar="3"
baz="'baz'"
></my-component>
npm test
Apache2