调试时缺少角度范围

时间:2016-10-24 09:49:53

标签: javascript angularjs google-chrome

我有控制器,我有这样的广播:

java.net.SocketTimeoutException: connect timed out
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
    at java.net.Socket.connect(Socket.java:529)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:570)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:158)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:411)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:525)
    at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:272)
    at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:329)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:172)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:923)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:158)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1031)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:230)
    at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:77)
    at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:981)
    at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:283)
    at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307)
    at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:384)
    at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:489)
    at com.google.api.client.auth.oauth2.Credential.intercept(Credential.java:217)
    at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:868)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
    at com.eai.ga.HelloAnalytics.getReport(HelloAnalytics.java:113)
    at com.eai.ga.HelloAnalytics.main(HelloAnalytics.java:44) 

收听广播的其他控制器:

$scope.seachColumn= function () {
    $scope.$broadcast('seachColumn', true);
}

我评论了行$scope.$on('seachColumn', function (event) { //console.log($scope); console.log('vuala'); }); ,然后使用Chrome浏览器我在行console.log($scope)上创建了beakpoint。当Chrome在此行停止并且在控制台中我尝试执行命令console.log('vuala')时,我收到错误:

console.log($scope)

但是,如果我取消注释第Uncaught ReferenceError: $scope is not defined行,那么此行会毫无错误地打印console.log($scope)

为什么会这样?

1 个答案:

答案 0 :(得分:0)

出于好奇(可能不是解决方案但可能很有趣),如果将该函数(包含日志调用)绑定到包含$ scope的作用域会发生什么?

$scope.$on('seachColumn', function (event) {
    //console.log($scope);
    console.log('vuala');
}.bind ( this )); // or whatever context makes sense.

天真地,undefined要么意味着$ scope还不存在(这似乎不太可能,因为调用function-as-argument的另一个函数成功),或者该函数存在于另一个上下文中并且日志调用看不到它(因为它在函数中作为参数)。