My application loads a large JSON file using a <script> tag. The JS file containing the JSON is around 280k in size and follows a standard JS definition:
var _countries = {"country:{"USA":{...},"GBR":{ ...},"FRA":{ ...}, etc, etc ...}}} ;
Upon launching the app, the JSON is loaded into memory and then I aim to copy it to a new $rootScope variable rather than just creating a reference to the original object. Once the copying is complete, I intend to delete the original _countries object.
$rootScope._countries= angular.copy(_countries) ;
_countries = null ;
However, I am unsure how to determine when the object has been fully copied before deleting the original _countries object. With JavaScript's asynchronous nature, I want to avoid the risk of $rootScope._countries not containing the full object prior to nullifying the original one.
Additionally, I'm curious if there is a more efficient way to copy the original object without relying on angular.copy().