尝试在 $interval
$window.open()
定义的窗口对象时,我遇到了相当奇怪的行为
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
输出
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
如您所见,第一个 console.log $scope.childWindow
正在输出一个完全定义的窗口对象。 $interval
内的所有其他内容仅输出 {}
。我试过不将 childWindow
附加到 $scope
对象,我试过将它附加到 self
。我也试过关注 this例子也有同样的行为。任何人都知道为什么会这样?非常感谢。
JSFiddle 演示:http://jsfiddle.net/U3pVM/15124/
最佳答案
我在浏览器中尝试了您的代码,在 $interval 函数中设置调试点时,控制台中记录了一个空对象,但右侧的 watch 检查器显示 $scope.childWindow 不为空。所以你可能只能使用 $scope.childWindow。
关于javascript - 在 $Interval 上清除窗口对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29802650/