Store Features

withLinkEntitiesMultiSelection

Generates a link[Collection]IdsSelected() method that connects the selected entity ids to component signals like input(), model() and Angular Signal Forms. Prebuilt version of withLink for withEntitiesMultiSelection: reads the [collection]IdsSelected computed, writes route through select[Collection]Entities with clearSelectionBeforeSelect (so each write replaces the selection, and an empty array clears it), and syncs are guarded with an order-insensitive ids equality — the selection map does not preserve the order of the ids it was given, so an order-sensitive compare would cause echo loops.

Requires withEntitiesMultiSelection to be used before it.

Examples

Two-way sync with a model()

const entity = type<Genre>();

export const GenresStore = signalStore(
  { providedIn: 'root' },
  withEntities({ entity }),
  withEntitiesMultiSelection({ entity }),
  // generates linkIdsSelected()
  withLinkEntitiesMultiSelection({ entity }),
);
@Component({
  /* ... */
})
export class GenreMultiSelectComponent {
  store = inject(GenresStore);

  // writes from the parent select the entities in the store,
  // selecting in the store updates the parent
  value = model<(string | number)[]>([]);
  valueField = form(this.store.linkIdsSelected(this.value));
}

Direct usage

const linked = store.linkIdsSelected();

linked.set(['1', '2']); // selects entities 1 and 2, replacing the selection
linked.set([]); // clears the selection
linked(); // => store.idsSelected()

API

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

Methods

// link[Collection]IdsSelected(options?) => WritableSignal<(string | number)[]>
{
  linkIdsSelected: (options?) => WritableSignal<(string | number)[]>;
  // or with collection 'product':
  linkProductIdsSelected: (options?) => WritableSignal<(string | number)[]>;
}

See withLink for the options parameter (syncWith, readFrom, writeTo, initialValueFrom, updateStoreWhen).

This feature passes noSetter: true, so no private _set method is generated — select/clear[Collection]Entities already covers that write.

State

No state signals are generated.

Props

No props are generated.