我试图从 ng-repeat 中的第二个查询中计算数组长度。
这是我的html:
<tbody>
<tr ng-repeat="j in jobpositions | filter:searchString | orderBy:'startdate'">
<td ng-init="applications(j.id)">{{jobapplicationsperjob.length}}</td>
</tr>
</tbody>
这是功能:
$scope.applications = function(jid){
var JobapplicationsPerJob = $resource('/ats/services/jobapplicationsperjob/:jid');
$scope.jobapplicationsperjob = JobapplicationsPerJob.query({jid:jid});
console.log($scope.jobapplicationsperjob);
}
这是控制台日志:
[$promise: Object, $resolved: false]
0: f
$promise: Object
$resolved: true
length: 1
__proto__: Array[0]
[$promise: Object, $resolved: false]
$promise: Object
$resolved: true
length: 0
__proto__: Array[0]
[$promise: Object, $resolved: false]
$promise: Object
$resolved: true
length: 0
__proto__: Array[0]
如您所见,它两次返回值 1,但在 HTML 中它始终为 0。