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