I am new to angular js. I have two ng-controller in two Html page. I want to share data from one controller into another controller. Here is the service i have created:
app.service('sharedProperties', function() {
var stringValue = 'test string value';
var objectValue = {
data: 'test object value'
};
return {
getString: function() {
return stringValue;
},
setString: function(value) {
stringValue = value;
},
getObject: function() {
return objectValue;
}
}
});
Here is controller1:
app.controller('FirstCtrl',function($scope,sharedProperties){
sharedProperties.setString("Hi");
});
Here is controller2:
app.controller('SeccondCtrl',function($scope,sharedProperties){
window.alert(sharedProperties.getString());
});
Instead of getting alert containing string 'Hi' i am getting 'test string value'.
NB. i am using FirstCtrl and SeccondCtrl in two HTML file. And after setting string from FristCtrl i redirect to the second HTML file .