2016-05-25 20 views
0

角度spyboostユーティリティラッパーを使用しています。私はこのためにそれを再フォーマットしようとしていますangular 1 style guide。私はその一部で苦労しています。私はそれのほとんどが正しいと思うが、angular.forEach関数は私を捨てている。私はエラーが発生しました。 '期待' {'と代わりに'結果 'が見えました。誰かが私を助けてくれますか?角度スタイルガイドの再フォーマット1.5

angular 
    .module('myMod') 
    .factory('MyService'); 
MyService.$inject = ['$rootScope', 'atmosphereService', 'atmosphere']; 

function MyService ($rootScope, atmosphere) { 
    return { 
     subscribe: subscribe, 
     getMessage: getMessage 
    }; 

    function subscribe (r) { 
     var responseParameterDelegateFunctions = ['onOpen', 'onClientTimeout', 'onReopen', 'onMessage', 'onClose', 'onError']; 
     var delegateFunctions = responseParameterDelegateFunctions; 
     var result = {}; 

     delegateFunctions.push('onTransportFailure'); 
     delegateFunctions.push('onReconnect'); 

     angular.forEach(r, function (value, property) { 
      if (typeof value === 'function' && delegateFunctions.indexOf(property) >= 0) { 
       if (responseParameterDelegateFunctions.indexOf(property) >= 0) 
        **result[property] = function (response) {** 
         $rootScope.$apply(function() { 
          r[property](response); 
         }); 
        }; 
       else if (property === 'onTransportFailure') 
        result.onTransportFailure = function (errorMsg, request) { 
         $rootScope.$apply(function() { 
          r.onTransportFailure(errorMsg, request); 
         }); 
        }; 
       else if (property === 'onReconnect') 
        result.onReconnect = function (request, response) { 
         $rootScope.$apply(function() { 
          r.onReconnect(request, response); 
         }); 
        }; 
      } else 
       result[property] = r[property]; 
     }); 

     function getMessage() { 
      var vm = this; 
      var request = { 
       url: '/chat', 
       contentType: 'application/json', 
       transport: 'websocket', 
       reconnectInterval: 5000, 
       enableXDR: true, 
       timeout: 60000 
      }; 

      request.onMessage(response); { 
       vm.$apply (function() { 
        vm.model.message = atmosphere.util.parseJSON(response.responseBody); 
       }); 
      } 
     } 
     return atmosphere.subscribe(result); 
    } 

} 

})(window.angular); 
+0

あなたは生命維持の閉鎖を持っていますが、オープニング '(関数(){'ご覧エラーのように見えるが、コピー/貼り付けが不完全であるように思えるしませんが表示されていないように見えます。 – shaunhusain

+0

getMessageが定義される前に購読が終了していないように見えますが、0になるはずのすべての{およびすべての}をカウントアップします。 – shaunhusain

答えて

0
if (responseParameterDelegateFunctions.indexOf(property) >= 0) 

その中括弧が欠けていますか?

if (responseParameterDelegateFunctions.indexOf(property) >= 0) { 
    result[property] = function (response) { 
      $rootScope.$apply(function() { 
        r[property](response); 
       }); 
      }; 
} 
else if (property === 'onTransportFailure') { 
    result.onTransportFailure = function (errorMsg, request) { 
     $rootScope.$apply(function() { 
      r.onTransportFailure(errorMsg, request); 
      }); 
     }; 
} 
else if (property === 'onReconnect') { 
    result.onReconnect = function (request, response) { 
     $rootScope.$apply(function() { 
       r.onReconnect(request, response); 
     }); 
    }; 
} 
+0

これは中括弧が欠けていました。 IFFEの外観? – CB1111

+0

実際には、最初のものの中のすべてのif文に中括弧がないように見えます。 – robjam

+0

IIFEについては、開いている角括弧の数を数えます。 を追加(function(){ を1にしてImmediately Invoked Function Expression – robjam

関連する問題