Angular2 Directive For React Component
After 0.3.0 or higher, ng2-react
has been changed to @ngui/react
. Here are the changes;
- Module
ng2-react
is changed to@ngui/react
. - Direvtive
ng2-react
is changed tongui-react
. - Class name
Ng2React
is changed toNguiReact
.
- Pass read-only props to React component
- Call a function in React component
- Fire event in React componet
- Set state of React componet
You need more? Please log a feature requirement
- Angular renders
ngui-react
component with the following attributes;
* `reactComponent`, A React component to render. Let's call it as MyComp.
* `reactProps`, react props for the React component, MyComp.
* `reactState`, the initial state to be used by MyComp
ngui-react
create and render React component using;
* `React.createElement()`
* `React.render()`
You can access react element and instance from Angular component.
- reactElement: the react element from React.createElement()
- reactInstance: the react instance from React.render()
-
install @ngui/react
$ npm install @ngui/react --save
-
import NguiReactModule to your AppModule
import { NgModule } from '@angular/core'; import { FormsModule } from "@angular/forms"; import { BrowserModule } from '@angular/platform-browser'; import { AppComponent } from './app.component'; import { NguiReactModule } from '@ngui/react'; @NgModule({ imports: [BrowserModule, FormsModule, NguiReactModule], declarations: [AppComponent], bootstrap: [ AppComponent ] }) export class AppModule { }
For full example, please check out app
directory to see the example of;
app.module.ts
- and
app.component.ts
.
class Hello extends React.Component {
render() {
return <div>Hello {this.props.name}</div>;
}
}
import { Component, ViewChild } from '@angular/core';
import { Hello } from "./hello"; // This is a react component
@Component({
selector: 'my-app',
template: `
<ngui-react
[reactComponent]="Hello"
[reactProps]="{name:'angular2 react wrapper'}">
</ngui-react>
`;
...
This module is only improved and maintained by contributors like you.
As a contributor, it's NOT required to be skilled in Javascript nor Angular2. You are only to be open-minded and interested in helping others. As a contributor, you do following;
- Updating README.md
- Improving code comments
- Answering issues and building FAQ
- Documentation
- Translation
In result of your active contribution, you will be listed as a core contributor on https://ng2-ui.github.io, and a member of ng2-ui too.
If you are interested in becoming a contributor and/or a member of ng-ui,
please send me email to allenhwkim AT gmail.com
with your github id.
$ git clone https://github.com/ng2-ui/react.git
$ cd react
$ npm install
$ npm start