npm.io
1.1.5 • Published 9 years ago

@capaj/react2angular

Licence
Apache2
Version
1.1.5
Deps
9
Vulns
10
Weekly
0
Stars
543
React to Angular: The easiest way to use React components in Angular 1

react2angular Build Status NPM Apache2

The easiest way to embed React components in Angular 1 apps! (opposite of angular2react)

Installation

npm install react2angular --save

Usage

1. Create a React component
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. Expose it to Angular
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.

3. Use it in your Angular 1 code
<my-component
  foo-bar="3"
  baz="'baz'"
></my-component>

Tests

npm test

License

Apache2