Since I need to use the data in multiple controllers, I have stored it in $rootScope.currentCache
. When the page loads, the data typically looks like this:
{
System: "Foo Bar",
StartDateTime: "2014-11-27T12:35:00"
}
(please disregard any formatting issues as they are not relevant).
In my controller, I have the following code snippet:
app.controller("CurrentController", function ($rootScope, $scope) {
console.log($rootScope.currentCache);
var currentData = $rootScope.currentCache;
//processDate() converts StartDateTime into a user-friendly format
currentData = processDate(currentData);
console.log($rootScope.currentCache);
});
The first console.log() displays the date as:
2014-11-27T12:35:00
However, the second console.log() shows the date as:
Nov 27th 2014 at 12:35pm
I find this confusing because the date processing is done on the separate currentData
variable.
Other controllers require the date in its original format. So, my question is why is this happening and how can I prevent it?