我正在从angular到Spring进行REST调用。我能够得到回复。当我尝试使用ng-repeat填充视图中的值时,屏幕上不会显示任何内容。
这是我的Angular Code此代码在showhidecontroller
中 var resuls = $http.post('http://localhost:8080/aeservices/AddConfig', dataobj);
resuls.success(function(data, status, headers, config) {
$scope.dbresponse= data;
$scope.messagetest = $scope.dbresponse[0].messages;
alert($scope.messagetest);
console.log( $scope.messagetest);
console.log(data);
});
这是我从API
收到的回复 [{
"data12": null,
"name": null,
"errors": ["error data1", "error data2"],
"messages": ["Configuration has been Added successfully", "Configuration has been Added successfully"]
}]
这是我的HTML
<table ng-controller="ShowHideController">
<tr ng-repeat="item in dbresponse[0].errors" >
<span><td align="left" class="validationMsg"><img src="images/red_bullet.gif" border="0" width="8" height="8" alt=""> 
{{item}}
</td></span></tr>
</table>
我尝试使用ng-repeat,声明自己这样的项目是$ scope.items = ['one','two','three','four']。即使这没有出现在HTML上。
答案 0 :(得分:2)
尝试使用data.data,
<强>控制器:强>
app.controller("listController", ["$scope", "$http",
function($scope, $http) {
$http.get('test.json').then(function(response) {
$scope.dbresponse = response.data;
});
}
]);
<强> HTML:强>
<table ng-controller="listController">
<tr ng-repeat="item in dbresponse[0].errors">
<td align="left" class="validationMsg"><img src="images/red_bullet.gif" border="0" width="8" height="8" alt=""> {{item}}
</td>
</tr>
</table>
答案 1 :(得分:0)
请尝试以下代码,不要声明变量结果。
$http.post('http://localhost:8080/aeservices/AddConfig', dataobj).success(function(data, status, headers, config) {
$scope.dbresponse= data;
$scope.messagetest = $scope.dbresponse[0].messages;
alert($scope.messagetest);
console.log( $scope.messagetest);
console.log(data);
});
答案 2 :(得分:0)
发生的问题是我在HTML中声明了我的控制器两次