2016-11-29 6 views
0

Angular JSからRestを呼び出しています。 APIからの応答を取得するとng-repeatを使用してフロントエンドでメッセージを作成する予定です。これはコントローラのサイドコールです。Angular JSでng-repeatを使用してREST APIから値を取り込むことができません

 $http({ 
      url: "http://localhost:8080/services/AddConfig", 
      method: "POST", 
      data: dataobj, 
      headers: { 
       'Content-Type': 'application/json' 
      } 
     }).success(function(data, status, headers, config){ 
       responseData = data; 
       $scope.dbresponse = responseData; 
       console.log(responseData); 
       console.log($scope.dbresponse[0].messages); 
       console.log($scope.dbresponse[0].errors); 
       if($scope.dbresponse[0].messages[0] != null){ 
        console.log("success message"); 

        console.log("After Setting it"); 
       }else if ($scope.dbresponse[0].errors != null){ 
        console.log("has errors throw validation message"); 
       } 
     }).error(function(error){ 
       alert("Please Try again"); 
       }); 

コンソール

Object  
    errors:null 
    messages:Array[1] 
      0:Added Successfully 

私は何をしたい、そのメッセージにアクセスして行うにはNGリピートを使用して、フロントエンド.I'mに移入され、その失敗に見られるように、これは私のrepsonseです。

これは、あなたの 'dbresponse' の配列であると思われる私のHTMLあなたのAPI呼び出しの応答で

 <table> 
<tr ng-repeat="messages in dbresponse.messages"> 
<td align="left" class="validMsg"><img src="images/red_bullet.gif" border="0" width="8" height="8" alt="">&nbsp;{{messages}}</td></tr> 
</table> 

答えて

1

です:

はconsole.log($ scope.dbresponse [0] .messages) ;

< TR NG・リピート= "dbresponse.messages内のメッセージ" >

あなたの「responseDataの場合:

は、あなたのHTML内のに対して、あなたは、プロパティを持つ単一のオブジェクトとしてアクセス'はあなたのhtmlでそれをそのまま扱うかもしれない配列です。そうでない場合は、htmlの外観と '$ scope'に何が含まれているかについて少し詳しい情報を提供してください。

+1

Hey Filipe、それはタイプミスでした。私はこれだけのようにng-repeatを使用しようとしています 。このスコープのようにスコープを設定しています$ scope.dbresponse = responseData;スコープの内容は、質問と一緒に投稿しました。 – Praveen

関連する問題