fix(common): rename httpResource function in factory (#60022)

As the function in the factory was named `httpResourceRef`, error NG0203 had with the following message:

```
Error: NG0203: httpResourceRef() can only be used within an injection context such as a constructor, a factory function, a field initializer, or a function used with `runInInjectionContext`. Find more at https://angular.dev/errors/NG0203
```

PR Close #60022
This commit is contained in:
cexbrayat
2025-02-19 21:50:15 +01:00
committed by Miles Malerba
parent b14fbe1497
commit fc4a56d5c5
2 changed files with 7 additions and 1 deletions
+1 -1
View File
@@ -226,7 +226,7 @@ type ResponseType = 'arraybuffer' | 'blob' | 'json' | 'text';
type RawRequestType = (() => string | undefined) | (() => HttpResourceRequest | undefined);
function makeHttpResourceFn<TRaw>(responseType: ResponseType) {
return function httpResourceRef<TResult = TRaw>(
return function httpResource<TResult = TRaw>(
request: RawRequestType,
options?: HttpResourceOptions<TResult, TRaw>,
): HttpResourceRef<TResult> {
@@ -22,6 +22,12 @@ describe('httpResource', () => {
TestBed.configureTestingModule({providers: [provideHttpClient(), provideHttpClientTesting()]});
});
it('should throw if used outside injection context', () => {
expect(() => httpResource(() => '/data')).toThrowMatching((thrown) =>
thrown.message.includes('httpResource() can only be used within an injection context'),
);
});
it('should send a basic request', async () => {
const backend = TestBed.inject(HttpTestingController);
const res = httpResource(() => '/data', {injector: TestBed.inject(Injector)});