Store Features
Generates a link[Collection]IdSelected() method that connects the selected entity id to component signals like input(), model() and Angular Signal Forms. Prebuilt version of withLink for withEntitiesSingleSelection: writes route through select[Collection]Entity / deselect[Collection]Entity (setting undefined deselects).
Requires withEntitiesSingleSelection to be used before it.
const entity = type<Product>();
const collection = 'product';
export const ProductsStore = signalStore(
{ providedIn: 'root' },
withEntities({ entity, collection }),
withEntitiesSingleSelection({ entity, collection }),
// generates linkProductIdSelected()
withLinkEntitiesSingleSelection({ entity, collection }),
);
@Component({
/* ... */
})
export class ProductSelectComponent {
store = inject(ProductsStore);
// writes from the parent select the entity in the store,
// selecting in the store updates the parent
selectedId = model<string | number | undefined>(undefined);
linked = this.store.linkProductIdSelected({ syncWith: this.selectedId });
}
export class ProductSelectComponent {
store = inject(ProductsStore);
// reads store.productIdSelected(),
// writing selects/deselects the entity
selectedField = form(this.store.linkProductIdSelected());
}
withLinkEntitiesSingleSelection({ entity, collection? })
| Property | Description | Type |
|---|---|---|
entity |
The entity type | type |
collection |
The name of the collection (optional) | string |
// link[Collection]IdSelected(options?) => WritableSignal<string | number | undefined>
{
linkIdSelected: (options?) => WritableSignal<string | number | undefined>;
// or with collection 'product':
linkProductIdSelected: (options?) => WritableSignal<string | number | undefined>;
}
See withLink for the options parameter (syncWith, readFrom, writeTo, initialValueFrom, updateStoreWhen).
This feature passes noSetter: true, so no private _set method is generated — select/deselect[Collection]Entity already covers that write.
No state signals are generated.
No props are generated.