Arindam Barman
Arindam Barman

Reputation: 107

AngularJS Passing scope between controllers Performance

I have two AngularJS controllers where controller 1 is always visible in the view and controller 2 can change from view to view. I need to make sure that controller 1 has access to some scope variables. So on loading if I pass entire scope of controller 2 to controller 1 will it harm the performance of the page?

Upvotes: 0

Views: 83

Answers (1)

Robin Jonsson
Robin Jonsson

Reputation: 2851

Sharing scope between controllers is possible, but only through inheritence. I'm pretty sure you can't "send" a scope to another controller and replace it completely.

I would suggest either broadcasting events with data between controllers, or storing them inside AngularJS services (factory). Since these are singletons, the data will stay intact as long as you don't reboot the app.

EDIT: In regards to performance, even if the gain is extremely small, I'd suggest using a service to store the data. This way it's acting as a simple DTO, and doesn't have to be double-binding (if you don't need it) which means the $digest cycle is a bit faster.

Regards

Upvotes: 1

Related Questions