I'm encountering an issue with passing data from one controller to another using a service.
To achieve this, I have implemented prototype inheritance using the $rootScope
in my controller and broadcasting the object so that other controllers can access the data.
However, by utilizing $rootScope
, I am adding to the global namespace. I am looking for a way to transfer the data between controllers without polluting the global scope.
The scenario involves displaying minimal data in a table. Upon clicking on a specific record, I aim to display the complete data within the object.
This is how I currently manage it:
<tr ng-repeat="contact in filterContacts = (contacts.contactsData | filter:sensitiveSearch | orderBy:selectBox) " ng-style="{'background-color': contact.email == selectedContact.email ? 'lightgrey' : ''}" ng-click="selectContact(contact)">
In Controller A, I invoke this function from the view to pass the details of the selected row contact:
$scope.selectContact = function(contact) {
contactService.selectedContactInfo(contact);
};
Within the service, I simply return this data:
var selectedContactInfo = function(contact) {
return contact;
};
How can I retrieve this data in Controller B during the same event and display it on the view?
Reference Link: http://plnkr.co/edit/beOmiv?p=info
I prefer not to rely on $rootScope
but still want access to the data in the other controller.