Reputation: 2804
I want to pass big chunk of data from controller A to controller B.
so I made this factory
angular.module('MyApp')
.factory('holdCustomCover', function($scope, img_data) {
return {
save: $scope.img_data = img_data;
get: $scope.img_data;
}
})
am I doing it right? so later in controller A what should I do? like
holdCustomCover.save(myImgDataHere)
?
Then in controller B I do holdCustomCover.get()
I can get the img value?
Upvotes: 4
Views: 2496
Reputation: 136154
You can't inject $scope
inside factory
/service
funciton. Service/Factory are singleton object which are responsible for data sharing. You should have common code over there only.
In your code you have to create a function for getter & setter, which will return img_data
which is private data for holdCustomer
factory.
angular.module('MyApp')
.factory('holdCustomCover', function() {
var img_data; //private data
return {
//setter
save: function (data){
img_data = data;
},
//getter
get: function(){
return img_data;
}
}
})
Upvotes: 2