0

I'm working on web-app based on Angular 2. In Angular 1 we had two-way data-bindings, so services could be easily connected with page data using $scope (if we change something in service, data will be automatically updated).

In Angular 2 we have EventEmitter, I thought it's like Angular 1's $scope.$broadcast, so there could be performance issues with this.

What about performance of EventEmitters? Do they slow down application?

jumrifm
  • 55
  • 2
  • 8

1 Answers1

1

Events emitted by EventEmitter don't bubble and also don't broadcast. EventEmitters are for binding from child to parent only.

For broadcasting use shared services.

See also
- https://angular.io/docs/ts/latest/cookbook/component-communication.html#!#bidirectional-service
- updating variable changes in components from a service with angular2
- Delegation: EventEmitter or Observable in Angular2

Community
  • 1
  • 1
Günter Zöchbauer
  • 490,478
  • 163
  • 1,733
  • 1,404
  • Is there any performance benchmarks? In particular, how many EventEmitters effort app's performance? – jumrifm Apr 23 '16 at 11:41
  • 1
    I think `EventEmitters` are no burden for performance. They are (at least currently - might change in the future) `Observable` where an emitted event calls a callback on the subscribers. Events emitted by an `EventEmitter` can invoke Angulars change detection. It depends on your application and components how much work is actually to do when change detection is invoked. For example if you use `OnPush` then this might be cheap. With the default (`CheckAlways`) this can become pretty expensive. – Günter Zöchbauer Apr 23 '16 at 11:49