Follow by Email

AngularJS Sharing data between controllers

                                                         
This article is all about passing a data between controllers.
There are three ways to do it,

a) Using a service
b) Exploiting depending parent/child relation between controller scopes like $broadcast and $emit.
c) Using localStorage.


It is possible to send data from parent controller to a child controller and vice versa.
To transmit data from the First Controller to Second Controller, which the scope of the first one is parent to the scope of the second one, it should use $broadcast method in the First Controller.

Here is the javascript code:
Instead, if it need to send data from the SecondController (child) to the FirstController (parent), it should use the $emit method.

Here is the javascript code: