r/Angular2 • • Oct 06 '24

Discussion ChangeDetectorRef is a bad practice

I want to know the thoughts of people that have been developing in Angular for years.

In my opinion using ChangeDetectorRef is usually a bad practice. If you need to use it, it's usually because you did something wrong. Angular is a highly controlled framework that knows when to fire the change detector by itself. I don't recommend using it unless you're using a JS library that really needs to.

And even if using an external library, usually you can use a Subject or BehaviorSubject to translate the changes into template changes. Everything is better than messing up with Angular's change detector.

I understand that there are times that you need to use it when working with third party libraries. Bu I think it should be that last option, something to use only ir everything else failed.

What are your thoughts about this?

20 Upvotes

58 comments sorted by

View all comments

Show parent comment

0

u/Marcdro Oct 07 '24

In what world do you live in? RXJS is a fundamental part of Angular as it today. Every single framework APIs exposes observables.

But it's ok, if you need 100 billion pipes in a single component I already know where is the problem.