In my AngularJS application, I have two services. One service is used to declare objects with default values, while the other service is responsible for assigning new values to those objects. Everything works fine in the controllers after rewriting, but when I refresh the browser using Ctrl+F5, the objects are reinitialized to their default values.
I need assistance in resolving this issue.
The functionality works as expected initially, but upon refreshing using Ctrl+F5, it resets to the default value.
var appl = angular.module('app');
appl.service('service1', ['$rootScope', '$modal', function($rootScope, $modal) {
this.prefs = {
rememberMe: false,
popIt: function() {
$modal.open({
templateUrl: "views/flag-message.html",
controller: "flagMessageCtrl",
});
}
};
}]);
var appl = angular.module('app');
appl.service('service2', ['$rootScope', '$scope', 'service1', function($rootScope, $scope, service1) {
service1.prefs.rememberMe = true;
}]);
var appl = angular.module('app');
appl.controller('DemoCtrl', ['$scope', 'Restangular', 'service1', function ($scope, Restangular, service1) {
alert(service1.prefs.rememberMe);
}]);