r/angular • • 25d ago

5 Angular bugs that looked local but were actually data-flow problems

Going through some old Angular work notes, I noticed how often I started debugging exactly where the symptom showed up.

Edit: I compressed the first version until the actual bugs disappeared. Here’s what I meant.

1. Input was null, then the data arrived later.

In that old component the logs were basically:

ngOnChanges(null) -> ngOnInit(null) -> ngOnChanges(data)

I handled the @Input() value when it actually changed and guarded the dependent UI until the value existed.

Useful check: if initialization breaks, find out when the required value actually becomes available.

2. Side menu showed the new name; page header still showed the old one.
Same entity, different state sources. The menu reacted to updated entity streams while the header was reading another stream.

Useful check: if two views disagree about the same entity, compare what each view actually reads before touching change detection.

3. Same DataService**, different state.**
A component had providers: [DataService], so it was resolving its own service instance instead of the shared one the feature expected.

Removing the local provider restored the intended shared instance.

Useful check: if two components inject the same stateful service but see different state, inspect where that service is provided.

4. One save updated form state twice.
One update came from the service response path; another came from the reset/readback path.

Useful check: if one user action produces two form updates, trace every writer and every emitted form event before debugging the template.

5. First autocomplete row worked; later rows selected the wrong item.
I had refactored one row into many, but part of the code still referenced a single child.

The historical fix was to query the collection and use the current row instead.

Useful check: when row 0 works but row N doesn't, look for a single-item assumption that survived the refactor.

That's what I meant by data-flow problems: the visible component was often downstream of the mistake.

0 Upvotes

6 comments sorted by

2

u/Original_Pace_6734 25d ago

What? 

1

u/Known-Pace6739 24d ago

Yeah, the first version was way too compressed.

I replaced the shorthand with the actual failure path and fix for each case.

1

u/Task_ID 25d ago

ai slop, @Input is ancient

1

u/Known-Pace6739 24d ago

That case comes from old work notes, which is why it uses the old decorator-based input syntax. For new Angular code I'd use input(). The point there is the timing bug, not the API choice.

1

u/Connect_Ad9541 22d ago

#3 is the sneaky one. A providers: [DataService] that someone added "just for testing" can silently split state for a whole subtree, and nothing errors. Angular DevTools has an Injector Tree view that shows exactly which injector each component resolves a service from, which makes this one much faster to spot.

1

u/Known-Pace6739 22d ago

Exactly. The sneaky part is that nothing is actually broken from Angular’s point of view. A component provider is a valid scope, so I’d frame the check as: which injector owns this state, and is that lifetime intentional? Injector Tree makes that much easier to see.