In yesterday’s code challenge, our application wasn’t displaying any data. There were two reasons for that problem:
HttpClientwas not provided in the application- The change detection strategy
OnPushwasn’t compatible with the data flow of the application
I’m including links to previous newsletter entries for deeper dives on the different topics involved in that solution. And there are quite a few subtleties to overcome.
Let’s tackle the first issue, which was providing the HTTP client. We can use one of the several utility functions for standalone app config, in our case, provideHttpClient:

The second problem can be solved in two different ways:
- Remove change detection
onPushto use thedefaultone instead - Use the
asyncpipe or Signals to trigger change detection in thatOnPushcomponent
Because it’s always better to use the async pipe, I’m going with that option in our template:

In our component class, I stored the Observable from our service instead of storing the data. No more constructor needed:

You can see that solution in action on Stackblitz here. We fixed our code and added some performance improvements as well by ensuring we can’t get into memory leaks and optimizing change detection for that component.