Store Features

withLinkEntitiesSingleSelection

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.

Examples

Two-way sync with a model()

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 });
}

As a form field

export class ProductSelectComponent {
  store = inject(ProductsStore);

  // reads store.productIdSelected(),
  // writing selects/deselects the entity
  selectedField = form(this.store.linkProductIdSelected());
}

API

withLinkEntitiesSingleSelection({ entity, collection? })
Property Description Type
entity The entity type type()
collection The name of the collection (optional) string

Methods

// 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.

State

No state signals are generated.

Props

No props are generated.