ngxtension / ngxtension-platform

Utilities for Angular
https://ngxtension.netlify.app/
MIT License
592 stars 87 forks source link

feat(form-events): provide optional `injector` for both form event utils #509

Open michael-small opened 1 week ago

michael-small commented 1 week ago

I realized that since the util uses toSignal, it should be able to be given an injector optionally.

export function allEventsSignal<T>(
  form: AbstractControl<T>,
  injector?: Injector
): Signal<FormEventData<T>>;
export function allEventsSignal<T>(
  form: AbstractControl,
  injector?: Injector
): Signal<FormEventData<T>>;

export function allEventsSignal<T>(
  form: AbstractControl<T>,
  injector?: Injector
): Signal<FormEventData<T>> {
  return toSignal(allEventsObservable(form), {
    initialValue: {
      value: form.value, // <-- by the way, this will be .getRawValue() in #499
      status: form.status,
      pristine: form.pristine,
      touched: form.touched,
      valid: form.valid,
      invalid: form.invalid,
      pending: form.pending,
      dirty: form.dirty,
      untouched: form.untouched,
    }, injector: injector});
}

Should be easy enough but I have to make test scenarios, and I want to see if anyone else has any injection considerations I haven't accounted for. Thoughts?