As an extensive rxjs user, I find the rxResource method much more easier and intutive to use in my daily routine. Thanks for the great explanation. Love your videos...
@alissonprimo21 күн бұрын
Great explanation! Thanks! ❤
@tjlav523 күн бұрын
Value is T|undefined because the value is undefined until the loader resolves (or when a new request kicks off)
@CodeWithAhsan23 күн бұрын
Makes sense. Thanks for sharing!
@alm-r4w9 күн бұрын
unrelated the to the video but i would really like to hear your input on this: i work with angular for few years now and i mostly saw people design http request function in a way that it always returns the data directly in the component its used in. and i do so to bc i never thought of doing this differently. so only recently i discovered the idea of saving http requests in variable inside the service and then work with behaviour subjects to update components with the data from the that variable and work with behaviour subjects. And in every case where u use data data multiple times it seems way more logical and practical for statemanagement so i started using it this way almost everywhere except if i only need to get the data once in a single component. but since i rarely see it i wonder if there is a flaw in my thinking. What do u think is the best practice when it comes to this.
@CodeWithAhsan9 күн бұрын
@@alm-r4w great question. I think your approach is okay as well. however it requires a bit of care to not mess up. In the case of having the data in the service , you are still keeping the data in the service even if you’re not using it anymore. Or the purpose of the data has been fulfilled by being rendered on view. It will also make the testing a bit harder since your data is bound to your service . You won’t be able to mock it easily. The best practice I think it will be to receive the data from the API and to let it go, or save it into your state as required. In my opinion, request data, component state, and/or service variables shouldn’t be tightly coupled. The more isolation you have , the easier it is to perform unit tests.
@alm-r4w9 күн бұрын
@@CodeWithAhsan Ok i think i understand, so if in need of reusing the data cross multiple components u would work with two sepperate services one for the api fetching and one for state management?
@CodeWithAhsan9 күн бұрын
@@alm-r4w Exactly!
@nebojsazakic23 күн бұрын
Until the signal resolves the value is undefined. Please use ?? instead of ||.