Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Window object cleared on $Interval

I'm experiencing rather weird behavior when trying to log a window object defined by $window.open() in AngularJS within an $interval

self = this
$scope.childWindow = $window.open(authService.buildAuthorizeUrl(), '_blank')
console.log $scope.childWindow
var1 = "I may not work"
self.var2 = 'I should work'
privateData.authInterval = $interval ->
  console.log $scope.childWindow
  console.log var1
  console.log self.var2
,
  1000

Output

Window {document: document, window: Window, frameElement: null, clientInformation: Navigator, onhashchange: null…}
Window {}
I may not work
I should work
Window {}
I may not work
I should work 

As you can see, the first console.log $scope.childWindow is outputting a fully defined window object. All others, inside the $interval, are outputting only {}. I've tried not attaching childWindow to the $scope object, and I've tried attaching it to self. I've also tried following this example too and experienced the same behavior. Anyone have any idea why this is happening? Thanks much.

JSFiddle demo: http://jsfiddle.net/U3pVM/15124/

like image 901
Alex_Faber Avatar asked Nov 10 '22 15:11

Alex_Faber


1 Answers

I tried your code in a browser and while setting a debug point inside the $interval function an empty object is getting logged in the console but the watch inspector on the right shows that $scope.childWindow is not empty. So you might just be able to use $scope.childWindow.

enter image description here

like image 162
Rathish Cholarajan Avatar answered Nov 14 '22 22:11

Rathish Cholarajan