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?

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Is there any performance benchmarks? In particular, how many EventEmitters effort app's performance?
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.