我尝试使用下面的代码,但它返回表的空行(超过30+)。
JSON
"[{\"COMPANY_ID\":\"1\",\"COMPANY_DESC\":\"11\",\"COMPANY_CURRENCY\":\"1\",\"ACTIVE\":true,\"IS_HEADOFFICE\":true,\"ACCOUNTING_SYSTEM_ID\":\"1\"},{\"COMPANY_ID\":\"2\",\"COMPANY_DESC\":\"2\",\"COMPANY_CURRENCY\":\"22\",\"ACTIVE\":false,\"IS_HEADOFFICE\":false,\"ACCOUNTING_SYSTEM_ID\":\"1\"}]"
HTML
<tr ng-repeat = "company in companies track by $index"">
<td>{{ company.COMPANY_ID }}</td>
<td>{{ company.COMPANY_DESC }}</td>
<td>{{ company.COMPANY_CURRENCY }}</td>
</tr>
应用
<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("http://localhost:52087/api/accountmapping")
.success(function (response){
$scope.companies = angular.fromJson(response);
console.log(angular.fromJson(response));
});
});
</script>
答案 0 :(得分:0)
使用then
代替success
。自角度版本1.4
success
已被弃用
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("http://localhost:52087/api/accountmapping")
.then(function (response){
$scope.companies = response.data;
console.log($scope.companies);
});
});
答案 1 :(得分:0)
我尝试镜像您的代码,但我没有发现错误,请检查我的代码并告诉我我错过了哪些错误。
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
var myJsonAsText = '[{\"COMPANY_ID\":\"1\",\"COMPANY_DESC\":\"11\",\"COMPANY_CURRENCY\":\"1\",\"ACTIVE\":true,\"IS_HEADOFFICE\":true,\"ACCOUNTING_SYSTEM_ID\":\"1\"}, {\"COMPANY_ID\":\"2\",\"COMPANY_DESC\":\"2\",\"COMPANY_CURRENCY\":\"22\",\"ACTIVE\":false,\"IS_HEADOFFICE\":false,\"ACCOUNTING_SYSTEM_ID\":\"1\"}]';
var convertToJson = angular.fromJson(myJsonAsText);
console.log(convertToJson);
$scope.companies = convertToJson;
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="customersCtrl">
<ul>
<li ng-repeat = "company in companies track by $index"">
<p>COMPANY_ID: {{ company.COMPANY_ID }}</p>
<p>COMPANY_DESC: {{ company.COMPANY_DESC }}</p>
<p>COMPANY_CURRENCY: {{ company.COMPANY_CURRENCY }}</p>
<hr>
</li>
</ul>
</div>
&#13;
答案 2 :(得分:0)
我更新了Angular的版本。问题已经解决了。
https://ajax.googleapis.com/ajax/libs/angularjs/1.6.6/angular.min.js