move use of $window to controller.

Example doesn't work now. I got error that one can't use $window in expression, so I moved its use to controller.