【发布时间】:2017-01-14 06:52:06
【问题描述】:
我正在尝试手动将值添加到从 REST API 获得的响应中,并在 View 中使用它。问题是我无法访问 ng-repeat 中手动添加的项目。让我用我的例子来解释。这是我从 REST API 获得的搜索响应。我像这样为搜索响应添加了值。
$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
这是我的 HTML
<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>
我怎样才能得到那里显示的价值测试。我希望在另一个 switch 案例或 ng-if 案例中使用该值
【问题讨论】:
标签: html angularjs angularjs-scope