2017-01-13 8 views
0

私はREST APIから得た応答に手動で値を追加して、ビュー内で使用しようとしています。問題は、ng-repeatの中に手作業で追加したアイテムにアクセスできないことです。私の例を説明しましょう。これは私がREST APIから得た検索応答です。このような検索応答に値を追加しました。はng-repeat内で値を取得できません

$scope.searchresponse = [{ 
"items": [{ 
    "employeeId": "ABC", 
    "type": "D", 
    "alive": "Yes" 

}, { 
    "employeeId": "DEF", 
    "type": "D", 
    "alive": "Yes" 

}, { 
    "employeeId": "NPK", 
    "type": "D", 
    "alive": "Yes" 

}, { 
    "employeeId": "PKN", 
    "type": "A", 
    "alive": "Yes" 
}], 
"more": false 
}]; 
$scope.searchresponse.action = "Test" 
console.log($scope.searchresponse);// I am able to see the test value here 

これはどのように私は価値のテストが表示され得ることができます

<tr ng-repeat="details in searchresponse"> 
<td class=list align=center ng-switch="details.type"> 
<span 
ng-switch-when="D">SINGLE</span><span 
ng-switch-when="E">MULTIPLE</span> 
<td> {{$scope.searchresponse.action}}</td> // - Tried this didnt work 
<td> {{searchresponse.action}}</td> // - tried this didnt work . 
</td> 

私のHTMLです。別のスイッチのケースまたはng-ifの場合にその値を使用したいです

答えて

2

私は問題は$scope.searchresponseが配列で、それがオブジェクトのようなキーと値のペアを追加しようとしていると思います。何

$scope.searchresponse = {items: [<your-items-goes-here>], action: "test"} 

に構造を変えることについてあなたはng-repeat="item in searchresponse.items"とそれにアクセスすることができ、それがローカルになりますので、あなたはdetails見てNGリピート必要内部{{searchresponse.action}}

+0

:だから、いくつかのデータは次のようになりますバインディング。私が抱えている唯一の問題は、後で 'searchresponse'に追加されたアクション変数にアクセスすることです – Praveen

0

あなたのバインディングであなたのアクションを表示することができますスコープ、私はここで追加するのを忘れて(今の質問を更新しましたが)、私は `私のContrtoller内部の$ scope.searchresponse`を宣言した

<td> {{details.action}}</td> 
関連する問題