fixed error with scope.$apply