2016-03-21 14 views
0

この機能内からスコープを更新する際に問題が発生しましたupdateRefresh()。私はmessage == "test"、それがスコープ内に何上書きされないが、何それは私のHTMLページ上に結合され、<span>{{refreshDomainStatus.message}}</span>は、まだ私は$scope.$apply()をしようとしたが、それいるmessage="test"http呼び出しでスコープバインディングが更新されない

オブジェクトにバインドされていることがわかります最初の反復$digestが現在進行中であると言います。

app.controller('AssessmentController', ['$scope', '$http', '$timeout', 'ConnectionService', function ($scope, $http, $timeout, connectionService) { 

    $scope.refreshDomainStatus = { 
     message: "test" 
    }; 

    var updateRefresh = function(updateKey) { 
     $http.get('/assessment/api/update-refresh-domain/' + updateKey).success(function(response) { 
      $scope.refreshDomainStatus = response.refreshDomainStatus; 

      if (!response.refreshDomainStatus.halted) { 
       $timeout(function() { updateRefresh(updateKey); }, 250); 
      } 
     }); 
    } 

最初の反復: First Iteration

2回目の反復: After

+0

あなた 'はconsole.log(response.refreshDomainStatus)場合;'あなた 'updateRefresh()'メソッドの内部で、出力は何ですか?また、明白な質問ですが、ループ全体を開始するために 'updateRefresh()'をどこかに呼び出すのでしょうか? – Lex

+0

はい、私はそれを呼び出してプロセス全体をオフにします。最初の反復: 'response.refreshDomainStatus =>オブジェクト{エラー:偽、メッセージ:"ユーザのリストの取得 "、停止:偽}'。 '$ scope.refreshDomainStatus =>オブジェクト{エラー:真、メッセージ:"テスト "、停止:false}'。 2回目の繰り返しでは、$ scope.refreshDomainStatusが設定されています。それが正しいように思える。 '' test "と書かれている要素のスコープを調べると、次のようになります: – Bluebaron

答えて

1

はあなたがresponse.refreshDomainStatusから$scope.refreshDomainStatusを設定しない: Second Iteration

コンテキストを終えたし、検査した後?

$http.get('/assessment/api/update-refresh-domain/' + updateKey).success(function(response) { 
     $scope.refreshDomainStatus = response.refreshDomainStatus; 

     if (!response.refreshDomainStatus.halted) { 
      $timeout(function() { updateRefresh(updateKey); }, 250); 
     } 
    }); 
+0

はい。あなたが正しい。申し訳ありませんが、問題が参照の問題であるかどうかを確認しようとしていました。まだ動作しません。 – Bluebaron

+0

コンソールエラーを確認しましたか?あなたの$ httpは解決されていない可能性があります – amcpanaligan

+0

最初の反復:http://imgur.com/HLVzmHA 2回目の反復:http://imgur.com/mzxDewv終了時(コンソールのスコープの検査):http://imgur.com/DCfQ4Bh – Bluebaron

0

私の問題は、コントローラの2つのインスタンスを作成していたことでした。私はシングルトンのいくつかの並べ替えをしたいと思いますが、今後の参考のために、これは悪いです:

 <div class="row" ng-controller="AssessmentController"> 
      <div class="col"> 
       <button class="btn btn-default" ng-click="refresh()">Refresh</button> 
      </div> 

     </div> 
     <div ng-show="" class="row" ng-controller="AssessmentController"> 
      <div class="col"> 
       <span>{{refreshStatus.message}}</span>  
      </div> 
     </div> 
関連する問題