You should use $scope.$watch :
$scope.$watch(function(){ return $location.search() }, function(){
Learn more about $watch in Angular docs .
If you're just looking for the addition of "newview", the code above will be used to the query string.
i.e. from http://server/page to http://server/page?newvalue
However, if you are looking for a change in 'newview', the above code will not work.
ie from http://server/page?newvalue=a to http://server/page?newvalue=b
You will need to use the 'objectEquality' parameter to call $ watch. This leads to the fact that $ watch uses equality of value, instead of equality of references to objects.
$scope.$watch(function(){ return $location.search() }, function(){
Note the addition of the third parameter (true).
Maxim Grach Feb 14 '13 at 5:51 2013-02-14 05:51
source share