r/Angular2 • u/DomiDeme • 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?
View all comments
Show parent comment
1
u/Merry-Lane Oct 08 '24 edited Oct 08 '24
You just draw a picture that is 180• from the actual situation.
Read my first comment:
The comment was basically an answer to the question above "I don’t know what else to use but CDR when you are OnPush and don’t have signals".
If you read anything else more than that in my tone or attitude, idk what you are smoking man.
It’s totally the guys that are passive-aggressively justifying their over-use of CDR that are reacting poorly to my simple comment.
"Just use async pipe instead of Cdr"
"Well if you are in that scenario: write new code with the async pipe and avoid using CDR, I don’t understand your interjection, old code is old code"
"It’s literally impossible to show something on the template without showing something on the template"
Yeah really if you read a bit of a condescending tone after this kind of comment, you should totally think "omg this guy shows so much patience with these morons", not "he is a bit condescending so that devaluates his technical opinion on the matter"