Skip to content

Instantly share code, notes, and snippets.

@dragonfire1119
Last active December 17, 2015 04:19
Show Gist options
  • Save dragonfire1119/5549724 to your computer and use it in GitHub Desktop.
Save dragonfire1119/5549724 to your computer and use it in GitHub Desktop.
Angularjs transfer data to another controller. Found this on stack overflow saved me hours of looking.
angular.module('myApp.services', [])
.service('emailService', function ($rootScope){
var text = 'start value';
return {
saveEmail:function (data){
text = data;
$rootScope.$broadcast('new_message');
},
getEmail:function (){
return text;
}
};
});
function SignupCtl($scope, emailService) {
$scope.$on('new_message', function(){
window.alert(emailService.getEmail());
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment