Author avatar

Hristo Georgiev

React vs. Angular 2

Hristo Georgiev

  • Jan 10, 2019
  • 22 Min read
  • Jan 10, 2019
  • 22 Min read
Front-End JavaScript


This guide will provide a critical overview of two popular front-end web development tools - React and Angular 2. The tools will be evaluated based on their approaches to building application structure, adoption by the community, performance, and ability to integrate with different platforms.

The goal of this guide is to highlight core differences and understand the similarities between the two tools, thus facilitating the decision-making process when it comes to choosing which tool is appropriate for a given project specification.

Development flow

Angular 2

Angular 2 is very close to being a fully-fledged framework - it comes with many building blocks out of the box that cover most of the common scenarios in developing a web application. There is also a clear separation of the roles of the different elements:

  • Services - Injectable elements that are used to consume data from an API or share state between multiple components.
  • Components - Building blocks of the user interface that consume services. Can be nested inside each other through structural directive selectors.
  • Directives - Divided into structural and attribute directives. Structural directives (ex. \*ngFor) manipulate the DOM (Document Object Model) while attribute directives are part of elements and control their style and state.
  • Pipes - Used to format how data is displayed in the view layer.
  • Modules - Exportable blocks of the application that isolate components, directives, pipes, services and routes together.


React is far less rigid than Angular 2. It is a library that provides the most basic tools for building a web applications - a HTTP service and Components. There is no built-in router or anything that sets a particular convention. It is mostly up to the developer's choice what kind of packages he/she is going to use to shape the application.

Code structure

Angular 2

Angular 2 is written in TypeScript, a superset language of JavaScript developed by Microsoft. The language introduces types, new data structures and more object-oriented features, making the code easier to read and maintain compared to vanilla JavaScript. Initially, TypeScript's syntax was intended to be reminiscent of C#. However, recent veriouns of TypeScript feature the arrow (=>) notation and other ES6-specific syntax, making TS resemble more ES6.

Using TypeScript makes setting up an Angular 2 application somehow tedious, as it introduces extra overhead for configuration.


React is relying on JSX (Java Serialization to XML), an XML-esque syntax extension for rendering JavaScript and HTML. In terms of syntax and structure, JSX looks like JavaScript and appears to blend into HTML more easily. It allows the mixing of variables and JavaScript data structures within the HTMl markup.

To get a clearer comparison between React and Angular 2's code strucures, we are going to compare how a basic TODO application is built (example apps built by Mark Volkmann (mvolkmann).

Both applications use Webpack for development and deployment.

In terms of application structure, both React and Angular 2 need two files - TodoList which represents the list of tasks and Todo which represents a single task.

Let's analyze the TodoList component (todolist.component.ts for Angular 2 and todo-list.js for React, respectively) piece-by-piece, from top to bottom:


Angular 2
1import {Component} from '@angular/core';
2import {bootstrap} from from '@angular/platform-browser-dynamic';;
3import {TodoCmp, ITodo} from "./todoCmp";
1import React from "react";
2import ReactDOM from "react-dom";
3import Todo from "./todo";

Initializing a component

I've spotted the key differences between the tools using comments.

Angular 2
1// Used for type of state property in TodoListCmp class.
2// Both properties are optional, but preferred as they make
3// the code more maintainable.
4interface IState {
5  todos?: ITodo[];
6  todoText?: string;
9// This syntax is called a Decorator and is similar
10// to Annotations in other languages.  Decorators are
11// under consideration to be included in ES2016.
13  selector: 'todo-list',
14  template:`  ` /*This is where the markup for the template can be put.
15   Alternatively, you can reference a html file using templateUrl */
18export class TodoListCmp {
19  private static lastId: number = 0;
20  private state: IState;
22  constructor() {
23    this.state = {
24      todos: [
25        TodoListCmp.createTodo('learn Angular', true),
26        TodoListCmp.createTodo('build an Angular app')
27      ]
28    };
29  }
1let lastId = 0; // no static class properties in ES6
3class TodoList extends React.Component {
4  constructor() {
5    super(); // must call before accessing "this"
6    this.state = {
7      todos: [
8        TodoList.createTodo('learn React', true),
9        TodoList.createTodo('build a React app')
10      ]
11    };
12  }

Creating an item

Angular 2
1static createTodo(
2    text: string, done: boolean = false): ITodo {
3    return {id: ++TodoListCmp.lastId, text, done};
6onAddTodo(): void {
7    const newTodo: ITodo =
8      TodoListCmp.createTodo(this.state.todoText);
9    this.state.todoText = '';
10    this.state.todos = this.state.todos.concat(newTodo);
1static createTodo(text, done = false) {
2    return {id: ++TodoList.lastId, text, done};
5onAddTodo() {
6    const newTodo =
7      TodoList.createTodo(this.state.todoText);
8    this.setState({
9      todoText: '',
10      todos: this.state.todos.concat(newTodo)
11    });

As seen above, the creation process is quite similar for both tools, but React's is slightly shorter and appears to need less developer logic.

Detecting item states

Angular 2
1get uncompletedCount(): number {
2    return this.state.todos.reduce(
3      (count: number, todo: ITodo) =>
4        todo.done ? count : count + 1, 0);
1get uncompletedCount() {
2    return this.state.todos.reduce(
3      (count, todo) =>
4        todo.done ? count : count + 1, 0);

Reacting to changes

Angular 2
1onArchiveCompleted(): void {
2    this.state.todos =
3      this.state.todos.filter((t: ITodo) => !t.done);
6onChange(newText: string): void {
7    this.state.todoText = newText;
10onDeleteTodo(todoId: number): void {
11    this.state.todos = this.state.todos.filter(
12      (t: ITodo) => !== todoId);
15onToggleDone(todo: ITodo): void {
16    const id: number =;
17    this.state.todos =
18      (t: ITodo) => === id ?
19        {id, text: todo.text, done: !todo.done} : t);
1onArchiveCompleted() {
2    this.setState({
3      todos: this.state.todos.filter(t => !t.done)
4    });
7onChange(name, event) {
8    this.setState({[name]:});
11onDeleteTodo(todoId) {
12    this.setState({
13      todos: this.state.todos.filter(
14        t => !== todoId)
15    });
18onToggleDone(todo) {
19    const id =;
20    const todos = =>
21 === id ?
22        {id, text: todo.text, done: !todo.done} :
23        t);
24    this.setState({todos});


Angular 2
1//In Angular 2, chunks of the
2//application logic that are responsible for a certail feature
3//are encapsualted in a module
4import { NgModule } from "@angular/core";
5import { BrowserModule } from "@angular/platform-browser";
6import { TodoListCmp } from "./todoList.component";
8  imports: [BrowserModule],
9  declarations: [TodoListCmp],
10  bootstrap: [TodoListCmp]
12export class AppModule {}
13//An Angular module can import functionalities from other modules and export some of its building blocks to other modules.
1// src/main.ts
3import { platformBrowserDynamic } from "@angular/platform-browser-dynamic";
4import { AppModule } from "./app.module";
6//The module is bootstrapped, making the bootstrapped component the root //of the application if no routes are defined.
8const platform = platformBrowserDynamic();
1} // end of TodoList class
3// This renders a TodoList component
4// inside a specified DOM element.
5// If TodoList was used in more than one place,
6// this would be moved to a different JavaScript file.
8  <TodoList/>,
9  document.getElementById('container'));

Template syntax

Angular 2
1  // This is the value of the @Component template
2  // property above.  It was moved here for
3  // easy comparison with the React render method.
4  `<div>
5    <h2>To Do List</h2>
6    <div>
7      {{uncompletedCount}} of
8      {{state.todos.length}} remaining
9      <!-- Clicking this button invokes the
10           component method onArchiveCompleted. -->
11      <button (click)="onArchiveCompleted()">
12        Archive Completed
13      </button>
14    </div>
15    <br/>
16    <form>
17      <!-- [ngModel] tells where to get the value. -->
18      <!-- (input) tells what to do on value change. -->
19      <input type="text" size="30" autoFocus
20        placeholder="enter new todo here"
21        [ng-model]="state.todoText"
22        (input)="onChange($"/>
23      <button [disabled]="!state.todoText"
24        (click)="onAddTodo()">
25        Add
26      </button>
27    </form>
28    <ul>
29      <!--
30        This uses a for loop to generate TodoCmps.
31        #todo defines a variable to use within the loop.
32        [todo] sets a property on each TodoCmp.
33        (onDeleteTodo) and (onToggleDone) are outputs
34        from the TodoCmp, and they call functions
35        on TodoListCmp with emitted values.
36        deleteTodo receives a type of number.
37        toggleDone receives a type of ITodo.
38      -->
39      <todo *ngFor="let todo of state.todos" [todo]="todo"
40        (on-delete-todo)="onDeleteTodo($event)"
41        (on-toggle-done)="onToggleDone($event)"></todo>
42    </ul>
43  </div>
1render() {
2    // Can assign part of the generated UI
3    // to a variable and refer to it later.
4    const todos = =>
5      <Todo key={} todo={todo}
6        onDeleteTodo=
7          {this.onDeleteTodo.bind(this,}
8        onToggleDone=
9          {this.onToggleDone.bind(this, todo)}/>);
11    return (
12      <div>
13        <h2>To Do List</h2>
14        <div>
15          {this.uncompletedCount} of
16          {this.state.todos.length} remaining
17          <button
18            onClick={() => this.onArchiveCompleted()}>
19            Archive Completed
20          </button>
21        </div>
22        <br/>
23        <form>
24          <input type="text" size="30" autoFocus
25            placeholder="enter new todo here"
26            value={this.state.todoText}
27            onChange=
28              {e => this.onChange('todoText', e)}/>
29          <button disabled={!this.state.todoText}
30            onClick={() => this.onAddTodo()}>
31            Add
32          </button>
33        </form>
34        <ul className="unstyled">{todos}</ul>
35      </div>
36    );
37 }

The component code for Angular 2 is generally more verbose than React's. The only case we've covered where React requires more code is with bootstrapping. This disparity can be attributed to TypeScript. :void , :ITodo and other types are often seen in the TypeScript. Angular 2 style usually dictates that variables, function parameters, and function themselves must have a type in TypeScript. React does not have any of that, making the code more convenient for developers who prefer traditional, more succint JavaScript.

Angular 2 uses @Component decorators to specify the different constructs (services, directives, pipes) that it contains and to define its own properties. It also lets the developer specify a selector for the component and put the code for the template using the template property or the templateUrl if a separate file is used. The same applies for styles - there is an option to input styles directly using the styles property or to include an array of files using styleUrls. React does not have an analog for a component decorator and requires the template of the component to be included in the component file itself, thus limiting the options for customization and making the information about a component harder to interpret.

Angular 2 templates come with a specific convention for different elements:

  • * denotes a directive that manipulates the DOM. For example, *ngFor iterates over an array of values and creates a new element for each. *ngIf is used to denote whether an element can be seen or not.
  • [] denotes a property binding, indicating that the element receives a value from the component. It is used mostly to pass data to a child component to the parent.
  • () indicates an event binding (such as (click), which triggers a function in the components.
  • [()] indicates two-way binding, meaning that any changes to the data that are passed will be propagated.

React templates also come with their peculiarities. JSX blurs the line by HTML and JavaScript, providing its own markup. Even though it seems that the template is written in HTML, the markup is actually XML that is later parsed into HTML. Because of JSX, standard HTML property words are camel-cased or have diffeerent names - onclick in JSX is onClick. for (used in labels) becomes htmlFor because for is a reserved word in JavaScript (meaning for-loop).

Nesting components

Next, let's look into how the component for a single ToDo item looks like in Angular 2 and in React:

Angular 2
1import {Component, Input, Output, EventEmitter}
2  from 'angular2/angular2';
4export interface ITodo {
5  id: number;
6  text: string;
7  done: boolean;
11  selector: 'todo',
12  template: `
13    <li>
14      <input type="checkbox"
15        [checked]="todo.done"
16        (change)="toggleDone()"/>
17      <span [ng-class]="'done-' + todo.done">
18        {{todo.text}}
19      </span>
20      <button (click)="deleteTodo()">Delete</button>
21    </li>`
23export class TodoCmp {
24  // @Input allows this component to receive
25  // initialization values from the containing component.
26  @Input() todo: ITodo;
27  // @Output allows this component to
28  // publish values to the containing component.
29  @Output() onDeleteTodo:
30    EventEmitter<number> = new EventEmitter<number>();
31  @Output() onToggleDone:
32    EventEmitter<ITodo> = new EventEmitter<ITodo>();
34  deleteTodo(): void {
36  }
38  toggleDone(): void {
40  }
1import React from "react";
3// There are three ways to define React components.
4// This is the stateless function component form
5// which only receives data through "props".
6// A props object is passed to this function
7// and destructured.
8const Todo = ({ onDeleteTodo, onToggleDone, todo }) => (
9  <li>
10    <input type="checkbox" checked={todo.done} onChange={onToggleDone} />
11    <span className={"done-" + todo.done}>{todo.text}</span>
12    <button onClick={onDeleteTodo}>Delete</button>
13  </li>
16// Optional validation of props object.
17const PropTypes = React.PropTypes;
18Todo.propTypes = {
19  todo: PropTypes.object.isRequired,
20  onDeleteTodo: PropTypes.func.isRequired,
21  onToggleDone: PropTypes.func.isRequired
24export default Todo;

Because it is the main building block of a React application, the component offers greater flexibility in the way it can be structured. Stateless components are built with one-directional data flow in mind, leaving the majority of the logic to stay outside of the component itself. Angular 2 also offers similar functionality, but it does it with more complexity.

Application Architecture

Angular 2

angular 2 data flow Bi-directional data flow typical for MVC patterns

Angular 2 is using the standard bi-directional data flow model. Once an action is made, the data goes up to the service layer, then it goes back to the view. This way of manipulating data has been widely criticised because the state of the data can be changed both ways, resulting in inconsistencies.


react data flow Flux data flow

React uses Flux to construct its applications. Each action is sent to a dispatcher, which sends the new information to stores. The stores then update (mutate) the information and send it down to the views (controller-views), which listen for changes.


Redux Redux data flow

Redux is the cool kid on the block. Like Flux, it is based on one-directional data flow, but it manages the data in a different way.

An application that uses Redux has a global state that is shared among the whole application. When an action is made, it is sent to a dispatcher, which serves to make a HTTP call to the API. Then, the changes are sent to reducers - pure functions that specialize in managing a part of the global application state. For example, if your application has users, projects and items as models, each of the models will be part of the global state and there will be a set of reducers that take care of managing their state. Once the state is 'mutated' by the reducers, the new information is sent down to the view.

In this way, state of the application is kept in one place, providing for an easier state management.

Redux was first introduced for React as an alternative to simplify Flux. Because of that, Redux is more widely adopted in the React community.

Recently, Angular 2 has started adopting the Redux pattern for data flow by utilizing rxjs's observables to maintain the state of the data and using pure functions to manipulate it. Attemps have been made to build unidirectional data flow in Angular 2 applications, but the adoption of this technique is still low.


Performance is another critical point of comparison. It shows how Angular 2 and React handle under heavy load and gives predictions for future problems as the applications become bulkier and more difficult to optimize.

The following tests have been developed by Stefan Krauss (krausest). The tests are carried out with Selenium to emulate user actions and record the results (in miliseconds)


Both Angular 2 and React are seem on par, with Angular 2 having a slight advantage on all DOM manipulations except for creating new elements.

In terms of memory management, React outperforms Angular 2 by using less memory, especially after page load. This is mainly due to the fact that React itself is smaller-sized than Angular 2.

Cross-platform integration

The cross-platform development world has made a huge leaps since the massive adoption of mobile devices. Now, WebView-based tools for building cross-platform mobile applications are obsolete.

There are two tools that allow building of cross-platform applications with native capabilities for Angular 2 and React, respectively - NativeScript and React Native

NativeScript, built by Telerik (now Progress), is intended to enable native mobile applications to be built with Angular 2. Even though it has only 8k stars on Github, NativeScript is mature and comes with great documentation and numerous extensions. It preaches a "write once, run everywhere" methodology of developing cross-platform applications. Even though this is an efficient approach, it does not enable devleopers to use many platform-specific UI features.

On the other hand, React Native, developed by Facebook, gives React native capabilities. Compared to NativeScript, React Native is still young but quite popular and maturing quickly, boasting over 37k stars on GitHub. React Native uses a "learn once, write anywhere" approach to developing cross-platform applications. Instead of attempting to generalize different platforms like NativeScript does, Rect Native embraces their differences, offering different ways to construct UI for the different platforms. Recently, the Angular 2 team has started adopting React Native, making a renderer for it.


Angular 2 is just over 18k stars on Github. There are ~15 000 repositories on Github that contain "Angular 2" or "ng2" and are written in TypeScript

React, on the other hand, is over 53K stars on Github. There are 95, 500 repositories containing the word "react" in them, roughly over nine times more than what Angular 2 has.

Still, one of the big reasons for the large number of repositories is that React comes with just a few built-in functionalities and relies on its community to provide it with the needed tooling to develop full-scale applications.


Both Angular 2 and React have large communities and boast corporate backing. Even though they have different philosophies to how an application development must be approached, there is a place for both of them in the software development world.