Skip to content

About

🚑 How To Use React Components in Angular Directives

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How To Use React Components in Angular Directives

How to run this example in your browser

After cloning this project, run the following commands in your terminal. This will (1) install bower to the local node_modules, (2) run bower install using local Bower, and (3) open index.html in your default browser.

npm install
npm run install
npm start

How does this work?

Inside the directive link function, mount the React component to the element argument. Because the element argument is a jQuery-like object, use element[0] to get the DOM node. Then, using the controller attribute, the values and functions can be sent to the component as props.

function link(scope, element, attrs, controller) {
  // Render the React component
  var input = React.createElement(InputComponent, { onChange: controller.setMessage });
  React.render(input, element[0]);
  
  // Cleanup when destroyed
  element.on('$destroy', function() {
    React.unmountComponentAtNode(element[0]);
  });
}

About

🚑 How To Use React Components in Angular Directives

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages