◐ Shell
clean mode source ↗

output • Angular

To use output(), import the function from @angular/core.

import {output} from '@angular/core';

Inside your component, introduce a new class member and initialize it with a call to output.

@Directive({
  ...
})
export class MyDir {
  nameChange = output<string>();    // OutputEmitterRef<string>
  onClick    = output();            // OutputEmitterRef<void>
}

You can emit values to consumers of your directive, by using the emit method from OutputEmitterRef.

updateName(newName: string): void {
  this.nameChange.emit(newName);
}