DEV Community

Code Comparison: React vs Angular

Shriram on April 16, 2023

In this blog, I would like to compare and contrast two of the most popular ways to develop UI using JavaScript out there: React and Angular. I star...
Collapse
 
amir2mi profile image
Amir M. Mohamadi

Clearly React has cleaner syntax, my second choice after React would be Vue for sure.

Collapse
 
dylanwatsonsoftware profile image
Dylan Watson

I don't think it's that clear cut though. React is nice but Angular's ability to separate html from typescript code is actually quite good for debugging.

It means Angular's html will be much closer to reality than React in practice.

Collapse
 
brense profile image
Rense Bakker • Edited

Really? Html has an ng-if element?

Thread Thread
 
dylanwatsonsoftware profile image
Dylan Watson

Haha Obviously not BUT it will render just fine with it!

Thread Thread
 
mellunar profile image
mellunar

I'm confused about how {submitError && <p className='product-submit-error'>{submitError}</p>} is closer to a html element than <p class='product-submit-error' *ngIf="submitError">{{submitError}}</p>

Collapse
 
nermin_karapandzic profile image
Nermin Karapandzic

clearly you are biased, or you don't know what clean means.

Collapse
 
amir2mi profile image
Amir M. Mohamadi

I think it's more about personal preference, as I said if I wanted to use Angular ng-fied attributes, I would go for Vue.js.

Collapse
 
amar9312 profile image
Amardeep
export class HomeComponent {
    @Input() count!:number;
    @Output() setCount= new EventEmitter<number>();
  constructor() { }

}
Enter fullscreen mode Exit fullscreen mode

I think the class name should be ChildComponent if I am not wrong

Collapse
 
shriram27 profile image
Shriram

You're right., I have corrected it. Thank you for pointing out the error :)

Collapse
 
innoflash profile image
Innocent Mazando

We can all be religious about our preferences but honestly Angular is top notch with it's SRP approach to problems, no wonder it's the best for wiring enterprise apps. Think React is too free style to write something that's maintainable over time

Collapse
 
danielepecora profile image
Daniele Pecora

Can't really sympathize with react JSX mixing view with controller code. Angular has an approach that follows better the separation of concerns paradigma.

Collapse
 
xanderselorm profile image
Alexander Selorm Kubi

You can always use hooks in react to separate your business logics. 😊

Collapse
 
brownieboy profile image
Michael Brown

Putting stuff in separate files !== separation of concerns. Angular controllers and templates are joined at the him.

Collapse
 
danielepecora profile image
Daniele Pecora

"...The separation of concerns is achieved using modularization, encapsulation and arrangement in software layers."

An Angular distinguishes between this aspects of a project:
-Modules
-Components
-Services
-Templates
-Metadata
-Data binding
-Directives
-Dependency Injection

If this and separating the presentation layer into view and logic is not some kind of "encapsulating" then I don't know.

Collapse
 
webjose profile image
José Pablo Ramírez Vargas

In my mind, only Svelte exists. 😎

But if Svelte didn't exist, Vue would be my choice. React seems to be the grandpa now: Shaped the future, but the future has surpassed it.

Collapse
 
eternal21 profile image
Eternal21

React is great if you need to write some unmaintainable spaghetti code quickly. For anything enterprise related, that you'll actually need to support long-term Angular is the way to go.

Collapse
 
tryagain profile image
Mohamed M.

Angular natural separation of concern make it easier to read and pick-up as a newbie

Collapse
 
mellunar profile image
mellunar

Angular looks difficult, but I found it way better to learn than the React spaghetti. After Svelte, we shouldn't even talk about React anymore.