arrayEvent
Builder for array manipulation events.
Provides a fluent, discoverable API for array operations. Type in your IDE to see all available operations.
BREAKING CHANGE: Template is now required for add operations.
Supports both primitive and object array items:
- Primitive: Pass a single field definition → extracts field value directly
- Object: Pass an array of field definitions → merges fields into object
Presentation
function arrayEvent (arrayKey: string): {
append: <T extends ArrayItemDefinition >(
template: T,
) => AppendArrayItemEvent <T>;
prepend: <T extends ArrayItemDefinition >(
template: T,
) => PrependArrayItemEvent <T>;
insertAt: <T extends ArrayItemDefinition >(
index: number,
template: T,
) => InsertArrayItemEvent <T>;
pop: () => PopArrayItemEvent ;
shift: () => ShiftArrayItemEvent ;
removeAt: (index: number) => RemoveAtIndexEvent ;
};Returns
{ append: <T extends ArrayItemDefinition >(template: T) => AppendArrayItemEvent <T>; prepend: <T extends ArrayItemDefinition >(template: T) => PrependArrayItemEvent <T>; insertAt: <T extends ArrayItemDefinition >(index: number, template: T) => InsertArrayItemEvent <T>; pop: () => PopArrayItemEvent ; shift: () => ShiftArrayItemEvent ; removeAt: (index: number) => RemoveAtIndexEvent ; } -An object with methods for all 6 array operations
Parameters
| Name | Type | Description |
|---|---|---|
| arrayKey | string | The key of the array field to operate on |
Example usage
import { arrayEvent } from '@ng-forge/dynamic-forms';
// Object item: append { name, email } object
eventBus.dispatch(arrayEvent ('contacts').append([
{ key: 'name', type: 'input', label: 'Name' },
{ key: 'email', type: 'input', label: 'Email' }
]));
// Primitive item: append single value
eventBus.dispatch(arrayEvent ('tags').append(
{ key: 'tag', type: 'input', label: 'Tag' }
));
// Removing items (no template needed)
eventBus.dispatch(arrayEvent ('contacts').pop()); // Remove last
eventBus.dispatch(arrayEvent ('contacts').shift()); // Remove first
eventBus.dispatch(arrayEvent ('contacts').removeAt(2)); // Remove at index