Angular.js, React.js Integration

Source: Internet
Author: User

Essential knowledge

Requirejs, Angularjs, Reactjs, can see this blog written about the relevant content to understand the necessary knowledge.

Integrate Angular.js, React.js

I have mentioned the performance problem of angular.js in the love and hatred of Angular.js, and react.js based on virtual DOM rendering the page, the performance of the display, so the integration of react.js in the system.

Requirejs Configuration
Requirejs.config ({baseUrl:'/', paths: {' jquery ':' Libs/jquery-2.1.3/jquery.min ',' Angular ':' Libs/angular-1.3.15/angular.min ',' React ':' Libs/react-0.13.3/react.min ',//Use the Jsx method to write react, which relies on the following three files    //React JSX    ' Jsxtransformer ':' Libs/react-0.13.3/jsxtransformer ',//Require JSX    ' JSX ':' LIBS/REACT-0.13.3/JSX ',//Require text    ' text ':' Libs/react-0.13.3/text '}, Shim: {' Angular ': {deps: [' jquery '], exports:' Angular '},' React ': {exports:' React '}}, Waitseconds:0});
Timer Component Timer

Write timer components using REACTJS timer.
Note: The directory where the Jsx file is located should not be named JSX, otherwise it will cause parsing to fail .
Timer.js

//Dependent name must be react (initials), otherwise JSX cannot be found after parsing reactDefine ([' React '], function(React) {  varTimemessage = React.createclass ({render: function() {      varelapsed =Math. Round ( This. props.elapsed/ -);varseconds = elapsed/Ten+ (elapsed%Ten?"':'. 0 ');//Here JSX will resolve to return react.createelement ("P", NULL, "React have been successfully running for", seconds, "seconds.") ;      //So rely on name to be react, otherwise react-undefined      return  <p>React have been successfully running for {seconds} seconds. </P>;}  });varTimer = React.createclass ({getinitialstate: function() {      return{Now:New Date()}; }, Componentdidmount: function() {      varthat = This; SetInterval ( function() {That.setstate ({now:New Date()}); }, -); }, Render: function() {      varelapsed = This. State.now.getTime ()- This. Props.start.getTime ();return  <timemessage Elapsed={elapsed} />;}  });returnTimer;});
Angular.js Using REACT components
Define ([' Angularapp ',' React ',' Jsx!jsxdir/timer '  //Use jsx! XXXX form introduced], function (Angularapp, React, Timer) {  //Use the react component in the angular controller, similarly in the directive linkAngularapp.controller (' Welcomectrl ', [' $scope ', function($scope) {    varStart =New Date();    Timer = react.createfactory (timer); React.render (Timer ({start:start}),//div element in pagedocument.getElementById (' TESTJSX ')    ); }]);});
Page effects

Angular.js, React.js Integration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.