Make copy of $rootScope

I've got a $rootScope variable in my .run() function with very basic http request. Then within different controllers I change the request around by adding a suffix to the URL and adding in different headers and so on.

The problem is that if I edit the $rootScope variable in any controller it changes globally. I've tried making a copy of the $rootScope variable in various services and controllers that use it, but it still seems to change the value of the $rootScope variable.

An example:

Say the URL of the $rootScope variable is:

http://myurl.com/api

When I go to login I change it to:

http://myurl.com/api/login

by just concatenating 'login' to the end, but then when I go to logout, I want to change it to:

http://myurl.com/api/logout

but instead I get:

http://myurl.com/api/login/logout

There are 2 ways to handle it.

1> Don't change the URL, instead append to it like

$rootScope.URL+"login" //OR logout

2> Use angular.copy to copy your URL. This will avoid reference, and won't change $rootScope variable.

$scope.newURL = angular.copy($rootScope.URL);

Now you can edit $scope.newURL.