As I understand, we need $window for the timeout function.

Angular offers a $timoute service [1] with some additional benefits, so it's probably better to use this. It could be that it lacks the clearTimeout tough.

[1] http://docs.angularjs.org/api/ng.$timeout