Javascript 数组中的对象未显示在ng repeat中-AngularJS
我对AngularJS很陌生,在视图中显示数组中的对象时遇到了一些问题 我有以下javascript代码:Javascript 数组中的对象未显示在ng repeat中-AngularJS,javascript,arrays,angularjs,Javascript,Arrays,Angularjs,我对AngularJS很陌生,在视图中显示数组中的对象时遇到了一些问题 我有以下javascript代码: // list initialization: vm.latestInvoices = { invoices: []}; .... // adding function to viewmodel: vm.getLatestInvoices = getLatestInvoices; ... function getLatestInvoices() { consol
// list initialization:
vm.latestInvoices = { invoices: []};
....
// adding function to viewmodel:
vm.getLatestInvoices = getLatestInvoices;
...
function getLatestInvoices() {
console.log("Test 1234");
var servicename = "GetLatestInvoicesRequest";
var params = {};
httpCall(servicename, params).then(function (data) {
vm.latestInvoices = data;
console.log(data);
return vm.latestInvoices;
})["catch"](function (data) {
console.log("getLatestInvoices error");
});
}
我的HTML视图:
<div class="col-lg-12">
<p id="overview-headline">Invoices Overview</p>
<div class="scrollCustomers" ng-init="vm.getLatestInvoices()">
<table class="table table-hover">
<thead>
<tr>
<th>Client</th>
<th>Project</th>
<th>ID</th>
<th>Inv. Date</th>
<th>Start Date</th>
<th>End Date</th>
<th>DKK ex VAT</th>
<th>CIG</th>
<th>Attention</th>
<th>Cust. Manager</th>
<th>Regarding</th>
<th>Due Date</th>
<th>Finalized</th>
<th>Paid</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="invoice in invoices">
<td>{{invoice.CompanyName}}</td>
<td>Project Name</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>Default</td>
<td></td>
<td></td>
<td></td>
<td>N/A</td>
<td>N/A</td>
<td>N/A</td>
</tr>
</tbody>
</table>
</div>
</div>
发票概述
客户
项目
身份证件
发票日期
开始日期
结束日期
丹麦克朗增值税
烟
敬告
卡斯特。经理
关于
到期日
定稿
支付
{{invoice.CompanyName}
项目名称
违约
不适用
不适用
不适用
在Googledev控制台中,数组及其对象返回良好。该视图不返回默认值、项目名称、默认值和N/A,因此我猜测由于某种原因,从未调用ng repeat中的发票
提前谢谢 将结果附加到
$scope
:
httpCall(servicename, params).then(function (data) {
vm.latestInvoices = data;
console.log(data);
$scope.invoices = data;
})["catch"](function (data) {
console.log("getLatestInvoices error");
});
}
您在哪里定义
httpCall
?它是从一个$http
promise链接而来的,您在那里执行了。然后(函数(响应){return response.data})
?httpCall是在同一个控制器中声明的函数。它返回我的JSON,工作正常!:)您是如何调用控制器的?您是否使用了controllerAs语法?还是你做的很普通?函数概览Ctrl(…….)var vm=this;您是否使用了ng controller=“OverviewCtrl as vm”
?例如?函数getLatestInvoices(){console.log(“Test 1234”);var servicename=“GetLatestInvoicesRequest”;var params={};httpCall(servicename,params)。然后(函数(data,$scope){vm.latestInvoices=data;console.log(data);$scope.invoices=data;})[“catch”](函数(数据){console.log(“getLatestInvoices error”);}不需要在函数中插入$scope
。