Angular Modernizer
    Preparing search index...

    Function collectEventHandlers

    • Event bindings named in events, in source order.

      Parses a single Angular template with @angular/compiler and returns every event binding with a given name, split into the calls and assignments its handler expression makes and whether each of them reads $event.

      Parameters

      • content: string

        Raw template text.

      • events: readonly string[]

        Event names (formError, valueChange for [(value)]).

      Returns TemplateEventHandler[]

      [] when the template cannot be parsed or the compiler is mocked.

      Pure function over template text, like inspectTemplate. Which element matches which directive, and which class method a call reaches, is resolved one level up in OutputFlowTracer. Element offsets use the same convention as inspectTemplate (offset of the tag name), so both results can be joined by position.

      A two-way binding [(value)]="x" yields the event valueChange; its handler is reported as the assignment x = $event that Angular performs.

      const handlers = collectEventHandlers('<app-item (saved)="onSave($event)"></app-item>', ['saved']);
      // [{ event: 'saved', tag: 'app-item', handler: 'onSave($event)',
      // steps: [{ kind: 'call', member: 'onSave', args: [{ index: 0, text: '$event', usesEvent: true }] }] }]