SlideShare a Scribd company logo
1
Comparing React and
Angular
Discussion Agenda
• React and Angular Tool Overview
• Side-By-Side Comparison
• Sample Code
• Architectural Comparisons:
• Component Tree Architecture
• Angular Digest Cycle
• React Virtual DOM
• Data Binding
• Big Picture Comparison
2
Overview
3
Angular is a Framework for
building Web Applications.
React is a JavaScript Library
for building User Interfaces.
Overview
4
Different problems are often best solved using different
tools. We will be discussing the features of React and
Angular and how they are both best suited for building
different types of Single Page Applications.
Overview – Developer Interest
5
Interestingly, in the 2017 Stack Overflow survey, React is
the most loved technology, while AngularJS is the most
used web development technology.
In general, developers tend to enjoy working with React
very much, while architectural decisions tend to be made
favoring Angular.
https://insights.stackoverflow.com/survey/2017#technology
Overview - Angular
6
• TypeScript-based open-source front-end web
application platform for building single page
applications.
• Uses component based architecture.
• Creates components by grouping structure and
function into HTML templates.
• Developers use components to build apps
declaratively.
• Provides simple framework solutions for
foundational functionality (routing, HTTP, forms,
etc) which can be customized.
• Digest cycle re-renders entire view when
data is updated.
• Functionality is organized into modules which
are loaded dynamically.
• Angular apps are loosely MVC, MVW, etc.
• Angular apps need to be built
Overview – React
7
• JavaScript library for building user interfaces.
• Uses components to build UIs.
• React components manage their own internal
state
• Components are written in JavaScript and JSX
• Only contains library functions for building views
• Builds views from encapsulated components
so UI only updates necessary elements when
data changes.
• All components contain structure by
implementing render() function which returns
HTML.
• React library is light, and needs outside tools to
serve, reuse components, etc.
• Standard tools exist, however (ex. create-react-
app
• React Uis also need to be built.
Side-By-Side Comparison of Angular and React - Stats
8
Side-By-Side Comparison of Angular and React - Features
9
Sample Code
<form (ngSubmit)="onSubmit(heroForm)"
#heroForm="ngForm">
<div class="form-group">
<label for="name">Name
<input class="form-control" name="name"
required [(ngModel)]="hero.name">
</label>
</div>
<button type="submit"
[disabled]="!heroForm.form.valid">Submit</b
utton>
</form>
<div [hidden]="!heroForm.form.valid">
{{submitMessage}}
</div>
10
var Saves = React.createClass({
getInitialState: function(){
…..
},
handleSubmit: function(e) {
…
},
render: function() {
var savedText = '';
var submitText = 'Save';
if (this.state.saved) {
savedText = 'You have saved this home.';
submitText = 'Remove';
}
return (
<div className="saves">
<form onSubmit={this.handleSubmit}>
<input type="submit" value={submitText} />
</form>
{this.state.numSaves} saves. {savedText}
</div>
);
}
});
JavaScript in HTML!
JS Render function
contains HTML!
Angular Template React JS Class
Review: Component Based Architecture
• Components are UI elements
which encapsulate functionality
and structure.
• Components are custom HTML
elements which contain HTML
coupled with functionality defined
in JavaScript.
• Components also contain an
isolated data scope. React
components use their isolated
scope to independently update the
view when bound data changes.
• The DOM is a tree of
components. There is a root
component and child components
as in the basic DOM.
11
How Angular Renders Components
• Angular components exist in TypeScript Component files and their corresponding
HTML template files.
• Angular renders a view by loading the base component (defined in the base module)
in TypeScript code and rendering the resulting tree of components.
• When Angular renders a component, it loads the component TypeScript code into
memory, then renders the resulting augmented HTML into the browser by parsing
the HTML template file and adding functionality (events, bound data, etc) from the
component code.
• When data bound to the view changes, the framework Digest Cycle is triggered to
refresh the rendered view.
• The Digest Cycle checks all databindings and updates any necessary values in the
augmented HTML, then re-renders the entire HTML DOM tree to refresh the page.
12
+ =
How React Renders Components
• React components exist in JS files which contain HTML embedded into JSX.
• A React view is built from independent components with isolated states.
• The base ReactDOM.Render() JavaScript method renders the view by calling the render()
method on each element in the DOM tree. Render() returns HTML.
• Conceptually, components are like JavaScript functions. They accept arbitrary inputs (called
“props”) and return React elements describing what should appear on the screen.
• The view consists of independent components which are only updated when the individual
state changes.
• When data bound to a React element changes, the render() method is triggered on the
element and it is updated in isolation.
13
Every React component
has a Render() method
React Virtual DOM
• React handles the DOM
considerably more efficient than
Angular’s Digest Cycle does.
• React keeps a copy of the DOM in
memory, called the Virtual DOM.
• When data on any component
changes, React updates the Virtual
DOM node associated with the
updated data.
• After updating the Virtual DOM,
React diffs it with the actual DOM.
• React uses the results of the diff to
re-render any updated component
on the actual DOM.
14
Angular Digest Cycle
15
• The Digest Cycle is the process by which Angular updates the view
after model data has been updated.
• The Angular framework registers a watch on all data bound
elements.
• When a data bound element changes, (or the digest cycle is
manually triggered in code), the framework evaluates every data
bound element to check if the value has changed.
• The framework re-renders the entire DOM with the updated data.
Data Binding
16
• Angular uses 2 – Way Data Binding, where any updates on the UI
are bound to the model automatically, and any model updates
(service, async communication, etc) are immediately visible to the
UI. Updating any piece of data triggers the Digest Cycle.
• React uses 1 – Way Data Binding, where updates to the UI trigger
events which call functions on the data model that update the data
and state. Remember that components have individual data
models.
Disclaimer: Angular has
optimized the Digest Cycle to
work more efficiently, but I
will leave the details for a
further discussion
Big Picture Comparison
• Angular’s Digest Cycle updates the entire
view when any data bound to a UI element is
updated.
• Angular is a framework, so it contains a lot of
useful of out-of-the box functionality that React
would require customization to implement.
• Angular is versioned and the standard
implementation is well documented by Google.
• Angular has a difficult learning curve, and in
general is harder to debug than React.
• The Angular CLI makes setup and development
very easy, however.
17
• React diffs DOM updates using a copy of the
DOM in memory and only updates relevant
view components when data is updated.
• The React landscape is quite mature,
however, and it is easy to find tools to help
streamline development. As a result, React
apps are typically coupled with other JS
libraries.
• There is no standard React project
configuration, and only a set of best practices
(Redux, Flux, ect)
• In my experience, React is easier to debug
because the render() method is exposed in
source code.
• Use the create-react-app tool to do (almost)
as much as the Angular CLI
Another Comparison Table

More Related Content

What's hot

React js Online Training
React js Online TrainingReact js Online Training
React js Online Training
Learntek1
 
React js for beginners
React js for beginnersReact js for beginners
React js for beginners
Alessandro Valenti
 
Reactjs
Reactjs Reactjs
Reactjs
Neha Sharma
 
React Js Simplified
React Js SimplifiedReact Js Simplified
React Js Simplified
Sunil Yadav
 
Intro to React
Intro to ReactIntro to React
Intro to React
Eric Westfall
 
Angular View Encapsulation
Angular View EncapsulationAngular View Encapsulation
Angular View Encapsulation
Jennifer Estrada
 
React JS - A quick introduction tutorial
React JS - A quick introduction tutorialReact JS - A quick introduction tutorial
React JS - A quick introduction tutorial
Mohammed Fazuluddin
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
Lohith Goudagere Nagaraj
 
React render props
React render propsReact render props
React render props
Saikat Samanta
 
Introduction to react js
Introduction to react jsIntroduction to react js
Introduction to react js
Aeshan Wijetunge
 
Introduction to ReactJs & fundamentals
Introduction to ReactJs & fundamentalsIntroduction to ReactJs & fundamentals
Introduction to ReactJs & fundamentals
websyndicate
 
React js
React jsReact js
React js
Nikhil Karkra
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation洪 鹏发
 
ReactJs
ReactJsReactJs
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
Bethmi Gunasekara
 
Its time to React.js
Its time to React.jsIts time to React.js
Its time to React.js
Ritesh Mehrotra
 
React introduction
React introductionReact introduction
React introduction
Kashyap Parmar
 
Introduction to Spring MVC
Introduction to Spring MVCIntroduction to Spring MVC
Introduction to Spring MVC
Richard Paul
 
Introduction to React
Introduction to ReactIntroduction to React
Introduction to React
Rob Quick
 
React.js
React.jsReact.js

What's hot (20)

React js Online Training
React js Online TrainingReact js Online Training
React js Online Training
 
React js for beginners
React js for beginnersReact js for beginners
React js for beginners
 
Reactjs
Reactjs Reactjs
Reactjs
 
React Js Simplified
React Js SimplifiedReact Js Simplified
React Js Simplified
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
Angular View Encapsulation
Angular View EncapsulationAngular View Encapsulation
Angular View Encapsulation
 
React JS - A quick introduction tutorial
React JS - A quick introduction tutorialReact JS - A quick introduction tutorial
React JS - A quick introduction tutorial
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
 
React render props
React render propsReact render props
React render props
 
Introduction to react js
Introduction to react jsIntroduction to react js
Introduction to react js
 
Introduction to ReactJs & fundamentals
Introduction to ReactJs & fundamentalsIntroduction to ReactJs & fundamentals
Introduction to ReactJs & fundamentals
 
React js
React jsReact js
React js
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
 
ReactJs
ReactJsReactJs
ReactJs
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
 
Its time to React.js
Its time to React.jsIts time to React.js
Its time to React.js
 
React introduction
React introductionReact introduction
React introduction
 
Introduction to Spring MVC
Introduction to Spring MVCIntroduction to Spring MVC
Introduction to Spring MVC
 
Introduction to React
Introduction to ReactIntroduction to React
Introduction to React
 
React.js
React.jsReact.js
React.js
 

Similar to Comparing Angular and React JS for SPAs

Reactjs notes.pptx for web development- tutorial and theory
Reactjs  notes.pptx for web development- tutorial and theoryReactjs  notes.pptx for web development- tutorial and theory
Reactjs notes.pptx for web development- tutorial and theory
jobinThomas54
 
Getting Started with React, When You’re an Angular Developer
Getting Started with React, When You’re an Angular DeveloperGetting Started with React, When You’re an Angular Developer
Getting Started with React, When You’re an Angular Developer
Fabrit Global
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
valuebound
 
Using Automatic Refactoring to Improve Energy Efficiency of Android Apps
Using Automatic Refactoring to Improve Energy Efficiency of Android AppsUsing Automatic Refactoring to Improve Energy Efficiency of Android Apps
Using Automatic Refactoring to Improve Energy Efficiency of Android Apps
Luis Cruz
 
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...
Edureka!
 
FRONTEND DEVELOPMENT WITH REACT.JS
FRONTEND DEVELOPMENT WITH REACT.JSFRONTEND DEVELOPMENT WITH REACT.JS
FRONTEND DEVELOPMENT WITH REACT.JS
IRJET Journal
 
Дмитрий Тежельников «Разработка вэб-решений с использованием Asp.NET.Core и ...
Дмитрий Тежельников  «Разработка вэб-решений с использованием Asp.NET.Core и ...Дмитрий Тежельников  «Разработка вэб-решений с использованием Asp.NET.Core и ...
Дмитрий Тежельников «Разработка вэб-решений с использованием Asp.NET.Core и ...
MskDotNet Community
 
Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016
Marco Breveglieri
 
Getting started with react &amp; redux
Getting started with react &amp; reduxGetting started with react &amp; redux
Getting started with react &amp; redux
Girish Talekar
 
Introduction to React JS.pptx
Introduction to React JS.pptxIntroduction to React JS.pptx
Introduction to React JS.pptx
SHAIKIRFAN715544
 
Introduction to ReactJS UI Web Dev .pptx
Introduction to ReactJS UI Web Dev .pptxIntroduction to ReactJS UI Web Dev .pptx
Introduction to ReactJS UI Web Dev .pptx
SHAIKIRFAN715544
 
Learning AngularJS - Complete coverage of AngularJS features and concepts
Learning AngularJS  - Complete coverage of AngularJS features and conceptsLearning AngularJS  - Complete coverage of AngularJS features and concepts
Learning AngularJS - Complete coverage of AngularJS features and concepts
Suresh Patidar
 
React.js at Cortex
React.js at CortexReact.js at Cortex
React.js at Cortex
Geoff Harcourt
 
Angular JS, A dive to concepts
Angular JS, A dive to conceptsAngular JS, A dive to concepts
Angular JS, A dive to concepts
Abhishek Sur
 
Angular 9
Angular 9 Angular 9
Angular 9
Raja Vishnu
 
Building reusable components as micro frontends with glimmer js and webcompo...
Building reusable components as micro frontends  with glimmer js and webcompo...Building reusable components as micro frontends  with glimmer js and webcompo...
Building reusable components as micro frontends with glimmer js and webcompo...
Andrei Sebastian Cîmpean
 
Tech Talk on ReactJS
Tech Talk on ReactJSTech Talk on ReactJS
Tech Talk on ReactJS
Atlogys Technical Consulting
 
AngularJS
AngularJSAngularJS
Angular js workshop
Angular js workshopAngular js workshop
Angular js workshop
Rolands Krumbergs
 
React & redux
React & reduxReact & redux
React & redux
Cédric Hartland
 

Similar to Comparing Angular and React JS for SPAs (20)

Reactjs notes.pptx for web development- tutorial and theory
Reactjs  notes.pptx for web development- tutorial and theoryReactjs  notes.pptx for web development- tutorial and theory
Reactjs notes.pptx for web development- tutorial and theory
 
Getting Started with React, When You’re an Angular Developer
Getting Started with React, When You’re an Angular DeveloperGetting Started with React, When You’re an Angular Developer
Getting Started with React, When You’re an Angular Developer
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
 
Using Automatic Refactoring to Improve Energy Efficiency of Android Apps
Using Automatic Refactoring to Improve Energy Efficiency of Android AppsUsing Automatic Refactoring to Improve Energy Efficiency of Android Apps
Using Automatic Refactoring to Improve Energy Efficiency of Android Apps
 
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...
 
FRONTEND DEVELOPMENT WITH REACT.JS
FRONTEND DEVELOPMENT WITH REACT.JSFRONTEND DEVELOPMENT WITH REACT.JS
FRONTEND DEVELOPMENT WITH REACT.JS
 
Дмитрий Тежельников «Разработка вэб-решений с использованием Asp.NET.Core и ...
Дмитрий Тежельников  «Разработка вэб-решений с использованием Asp.NET.Core и ...Дмитрий Тежельников  «Разработка вэб-решений с использованием Asp.NET.Core и ...
Дмитрий Тежельников «Разработка вэб-решений с использованием Asp.NET.Core и ...
 
Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016
 
Getting started with react &amp; redux
Getting started with react &amp; reduxGetting started with react &amp; redux
Getting started with react &amp; redux
 
Introduction to React JS.pptx
Introduction to React JS.pptxIntroduction to React JS.pptx
Introduction to React JS.pptx
 
Introduction to ReactJS UI Web Dev .pptx
Introduction to ReactJS UI Web Dev .pptxIntroduction to ReactJS UI Web Dev .pptx
Introduction to ReactJS UI Web Dev .pptx
 
Learning AngularJS - Complete coverage of AngularJS features and concepts
Learning AngularJS  - Complete coverage of AngularJS features and conceptsLearning AngularJS  - Complete coverage of AngularJS features and concepts
Learning AngularJS - Complete coverage of AngularJS features and concepts
 
React.js at Cortex
React.js at CortexReact.js at Cortex
React.js at Cortex
 
Angular JS, A dive to concepts
Angular JS, A dive to conceptsAngular JS, A dive to concepts
Angular JS, A dive to concepts
 
Angular 9
Angular 9 Angular 9
Angular 9
 
Building reusable components as micro frontends with glimmer js and webcompo...
Building reusable components as micro frontends  with glimmer js and webcompo...Building reusable components as micro frontends  with glimmer js and webcompo...
Building reusable components as micro frontends with glimmer js and webcompo...
 
Tech Talk on ReactJS
Tech Talk on ReactJSTech Talk on ReactJS
Tech Talk on ReactJS
 
AngularJS
AngularJSAngularJS
AngularJS
 
Angular js workshop
Angular js workshopAngular js workshop
Angular js workshop
 
React & redux
React & reduxReact & redux
React & redux
 

Recently uploaded

AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
ShamsuddeenMuhammadA
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 

Recently uploaded (20)

AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 

Comparing Angular and React JS for SPAs

  • 2. Discussion Agenda • React and Angular Tool Overview • Side-By-Side Comparison • Sample Code • Architectural Comparisons: • Component Tree Architecture • Angular Digest Cycle • React Virtual DOM • Data Binding • Big Picture Comparison 2
  • 3. Overview 3 Angular is a Framework for building Web Applications. React is a JavaScript Library for building User Interfaces.
  • 4. Overview 4 Different problems are often best solved using different tools. We will be discussing the features of React and Angular and how they are both best suited for building different types of Single Page Applications.
  • 5. Overview – Developer Interest 5 Interestingly, in the 2017 Stack Overflow survey, React is the most loved technology, while AngularJS is the most used web development technology. In general, developers tend to enjoy working with React very much, while architectural decisions tend to be made favoring Angular. https://insights.stackoverflow.com/survey/2017#technology
  • 6. Overview - Angular 6 • TypeScript-based open-source front-end web application platform for building single page applications. • Uses component based architecture. • Creates components by grouping structure and function into HTML templates. • Developers use components to build apps declaratively. • Provides simple framework solutions for foundational functionality (routing, HTTP, forms, etc) which can be customized. • Digest cycle re-renders entire view when data is updated. • Functionality is organized into modules which are loaded dynamically. • Angular apps are loosely MVC, MVW, etc. • Angular apps need to be built
  • 7. Overview – React 7 • JavaScript library for building user interfaces. • Uses components to build UIs. • React components manage their own internal state • Components are written in JavaScript and JSX • Only contains library functions for building views • Builds views from encapsulated components so UI only updates necessary elements when data changes. • All components contain structure by implementing render() function which returns HTML. • React library is light, and needs outside tools to serve, reuse components, etc. • Standard tools exist, however (ex. create-react- app • React Uis also need to be built.
  • 8. Side-By-Side Comparison of Angular and React - Stats 8
  • 9. Side-By-Side Comparison of Angular and React - Features 9
  • 10. Sample Code <form (ngSubmit)="onSubmit(heroForm)" #heroForm="ngForm"> <div class="form-group"> <label for="name">Name <input class="form-control" name="name" required [(ngModel)]="hero.name"> </label> </div> <button type="submit" [disabled]="!heroForm.form.valid">Submit</b utton> </form> <div [hidden]="!heroForm.form.valid"> {{submitMessage}} </div> 10 var Saves = React.createClass({ getInitialState: function(){ ….. }, handleSubmit: function(e) { … }, render: function() { var savedText = ''; var submitText = 'Save'; if (this.state.saved) { savedText = 'You have saved this home.'; submitText = 'Remove'; } return ( <div className="saves"> <form onSubmit={this.handleSubmit}> <input type="submit" value={submitText} /> </form> {this.state.numSaves} saves. {savedText} </div> ); } }); JavaScript in HTML! JS Render function contains HTML! Angular Template React JS Class
  • 11. Review: Component Based Architecture • Components are UI elements which encapsulate functionality and structure. • Components are custom HTML elements which contain HTML coupled with functionality defined in JavaScript. • Components also contain an isolated data scope. React components use their isolated scope to independently update the view when bound data changes. • The DOM is a tree of components. There is a root component and child components as in the basic DOM. 11
  • 12. How Angular Renders Components • Angular components exist in TypeScript Component files and their corresponding HTML template files. • Angular renders a view by loading the base component (defined in the base module) in TypeScript code and rendering the resulting tree of components. • When Angular renders a component, it loads the component TypeScript code into memory, then renders the resulting augmented HTML into the browser by parsing the HTML template file and adding functionality (events, bound data, etc) from the component code. • When data bound to the view changes, the framework Digest Cycle is triggered to refresh the rendered view. • The Digest Cycle checks all databindings and updates any necessary values in the augmented HTML, then re-renders the entire HTML DOM tree to refresh the page. 12 + =
  • 13. How React Renders Components • React components exist in JS files which contain HTML embedded into JSX. • A React view is built from independent components with isolated states. • The base ReactDOM.Render() JavaScript method renders the view by calling the render() method on each element in the DOM tree. Render() returns HTML. • Conceptually, components are like JavaScript functions. They accept arbitrary inputs (called “props”) and return React elements describing what should appear on the screen. • The view consists of independent components which are only updated when the individual state changes. • When data bound to a React element changes, the render() method is triggered on the element and it is updated in isolation. 13 Every React component has a Render() method
  • 14. React Virtual DOM • React handles the DOM considerably more efficient than Angular’s Digest Cycle does. • React keeps a copy of the DOM in memory, called the Virtual DOM. • When data on any component changes, React updates the Virtual DOM node associated with the updated data. • After updating the Virtual DOM, React diffs it with the actual DOM. • React uses the results of the diff to re-render any updated component on the actual DOM. 14
  • 15. Angular Digest Cycle 15 • The Digest Cycle is the process by which Angular updates the view after model data has been updated. • The Angular framework registers a watch on all data bound elements. • When a data bound element changes, (or the digest cycle is manually triggered in code), the framework evaluates every data bound element to check if the value has changed. • The framework re-renders the entire DOM with the updated data.
  • 16. Data Binding 16 • Angular uses 2 – Way Data Binding, where any updates on the UI are bound to the model automatically, and any model updates (service, async communication, etc) are immediately visible to the UI. Updating any piece of data triggers the Digest Cycle. • React uses 1 – Way Data Binding, where updates to the UI trigger events which call functions on the data model that update the data and state. Remember that components have individual data models. Disclaimer: Angular has optimized the Digest Cycle to work more efficiently, but I will leave the details for a further discussion
  • 17. Big Picture Comparison • Angular’s Digest Cycle updates the entire view when any data bound to a UI element is updated. • Angular is a framework, so it contains a lot of useful of out-of-the box functionality that React would require customization to implement. • Angular is versioned and the standard implementation is well documented by Google. • Angular has a difficult learning curve, and in general is harder to debug than React. • The Angular CLI makes setup and development very easy, however. 17 • React diffs DOM updates using a copy of the DOM in memory and only updates relevant view components when data is updated. • The React landscape is quite mature, however, and it is easy to find tools to help streamline development. As a result, React apps are typically coupled with other JS libraries. • There is no standard React project configuration, and only a set of best practices (Redux, Flux, ect) • In my experience, React is easier to debug because the render() method is exposed in source code. • Use the create-react-app tool to do (almost) as much as the Angular CLI