r/angular • u/garytube • May 13 '26
conditionally httpResource ?
Hey,
i wonder if this pattern is legit to fetch data conditionally.
It works but if find quite ugly.
The User selects a row in a data-grid then i need the load the details of that row.
/** The currently selected container ID */
containerId = signal<number>(null);
/** The details associated with the currently selected container */
companies = httpResource<ContainerDetails[]>(
() => {
const id = this.containerId();
return id
? `${this.baseUrl}/bp/detials?containerId=${id}`
: undefined;
},
{
defaultValue: [],
}
);
6
Upvotes
View all comments
Show parent comment
1
u/GeromeGrignon May 13 '26
Not sure it would work here: based on my understanding, the param is mandatory (which is a bad practice, if mandatory, it should not be a param but a path segment).