Search code examples
angulartypescriptangular-cliangular-decorator

Difference between EventEmitter vs Output Decorators in Angular-Cli


Why does EventEmitter and Output Decorator needs to be used together ?, I cannot see the difference between the two,

If they are required to be used together why not just one decorator to emit as well as bind to selector wherever it is used !

Appreciate any explanation !

Thank You


Solution

  • EventEmitter is just a Subject.

    @Output() is what marks the field as output for Angular event binding.

    I haven't tried in Angular TS, but in Angular Dart it was possible to just use a Stream (equivalent to Subject) instead of EventEmitter. In recent versions EventEmitter was removed completely in Dart Angular. Perhaps this works in Angular TS as well.

    There were plans to extends the API of EventEmitter in a way that might be incompatible with Subject, therefore a custom class was created.
    But there are no signs this will actually happen.