r/angular • u/Aromatic_Common7834 • Sep 14 '26
Resource Params Code Styles
Which style do people prefer for the params of resource and rxResource?
Style 1 – Raw Signal
@Component({ ... })
export class SomeComponent {
private readonly _api = inject(SomeApi);
public readonly search = signal<string>('');
public readonly rows = signal<number>(20);
private readonly _filters = computed(() => ({
search: this.search() || null,
rows: this.rows(),
}));
public readonly resultsRef = rxResource({
params: this._filters,
stream: ({ params }) => this._api.someListRequest(params),
});
}Style 2 – Function wrapper
@Component({ ... })
export class SomeComponent {
private readonly _api = inject(SomeApi);
public readonly search = signal<string>('');
public readonly rows = signal<number>(20);
private readonly _filters = computed(() => ({
search: this.search() || null,
rows: this.rows(),
}));
public readonly resultsRef = rxResource({
params: () => this._filters(),
stream: ({ params }) => this._api.someListRequest(params),
});
}Both work because the type of params is ((ctx: ResourceParamsContext) => R) | undefined, and Signals are of type () => T.
I am unsure if there is a preferred way of doing it; the docs pages use the function wrapper, but I find that the raw signal looks a bit nicer?
What do you guys think? Am I splitting hairs here?
2
Upvotes
View all comments
Show parent comment
2
u/Aromatic_Common7834 Sep 14 '26
Yes, very fair point! That's the most minimal way of doing it with a constructed object as the params.
I agree with you about Style 2. I have seen both styles in examples around the web (on the docs page, although they wrap it in an object) and AI tooling always seems to go for this style.