On Github willyg302 / angular-vs-react
William Gaul · ICS 419 Course Project
And...companies care about this stuff.
index.html
<h1>
<span id="greeting">Hello</span>
<span id="subject">world!</span>
</h1>
<select id="greetingInput">
<option value="Hello">Hello</option>
<option value="So long">So long</option>
</select>
<input id="subjectInput" type="text" value="world!">
app.js
var g = document.getElementById('greetingInput');
var s = document.getElementById('subjectInput');
g.onchange = function() {
document.getElementById('greeting').innerHTML = this.value;
};
s.onkeypress = s.onkeyup = function() {
document.getElementById('subject').innerHTML = this.value;
};
index.html
<body ng-app="App">
<div ng-controller="Example">
<h1>{{greeting}} {{subject}}</h1>
<select ng-model="greeting"
ng-options="g for g in greetings">
</select>
<input type="text" ng-model="subject">
</div>
</body>
app.js
angular.module('App', [])
.controller('Example', ['$scope', function($scope) {
$scope.greetings = ['Hello', 'So long'];
$scope.greeting = $scope.greetings[0];
$scope.subject = 'world!';
}]);
app.js
var App = React.createClass({
getInitialState: function() {
return { greeting: 'Hello', subject: 'world!' };
},
render: function() {
return ( /* Partial here */ );
},
onGreetingChange: function(event) {
this.setState({ greeting: event.target.value });
},
onSubjectChange: function(event) {
this.setState({ subject: event.target.value });
}
});
React.renderComponent(<App/>, document.body);
Partial
<div>
<h1>{this.state.greeting} {this.state.subject}</h1>
<select value={this.state.greeting}
onChange={this.onGreetingChange}>
<option value="Hello">Hello</option>
<option value="So long">So long</option>
</select>
<input type="text" value={this.state.subject}
onChange={this.onSubjectChange} />
</div>
“It is very helpful indeed if the framework guides developers through the entire journey of building an app.”
— The Zen of Angular
“We should do our utmost to shorten the conceptual gap between the static program and the dynamic process.”
— Edsger Dijkstra
Angular exists to aid the developer as much as possible in the present.
React is a preparation for the future.
What is the best sorting algorithm?
Which is better, Angular or React?
“If the only tool you have is a hammer, you tend to see every problem as a nail.”
— Abraham Maslow