I have a services.js file where I placed my facotry:
.factory('dataShare',function($rootScope){
var service = {};
service.data = false;
service.sendData = function(data){
this.data = data;
$rootScope.$broadcast('data_shared');
};
service.getData = function(){
return this.data;
console.log('this.data')
};
return service;
})
And my controllers, in the controller.js file look like this:
.controller('recommendedJobsCtrl', function($q,$scope, $ionicSideMenuDelegate,$window,$http,dataShare) {
$scope.text='hey';
$scope.post=function(){
dataShare.sendData($scope.text);
console.log('here')
}
})
.controller('jobPostCtrl', function($scope,$ionicSideMenuDelegate,dataShare) {
$scope.text = '';
$scope.$on('data_shared',function(){
var text = dataShare.getData();
$scope.text = text;
console.log(text)
});
})
When I did console.log, i realized that the service.getData isn’t wokring, i.e the receiving controller (jobPostCtrl) isn’t getting anything.
How can i fix this?