I have a large JSON that I load into my app via a <script>
tag. the JS file that contains the JSON is about 280k. It is a standard JS definition:
var _countries = {"country:{"USA":{...},"GBR":{ ...},"FRA":( ...}, etc, etc ...}}} ;
It is loading into memory as the app launches and then I want to copy it to a new $rootScope
variable, not just a reference to the original object, and then after its fully copied I want to delete the original _countries
object.
$rootScope._countries= angular.copy(_countries) ;
_countries = null ;
But how can I tell when the object is fully copied before fully deleting the original _countries
object? JS being asynchronous, I don’t want to risk $rootScope._countries
not having the full object before the null wipes out the original.
Also, is there a better way to copy the original object than using angular.copy()
?