fix the bug that $rootScope is not accessed outside angular

 - $rootScope.$apply() must wrap the code that access $rootScope
   variables in the outside angular world