如何触发ng-repeat内的功能

时间:2014-07-15 09:58:22

标签: javascript angularjs angularjs-ng-repeat angularjs-ng-init

我试图从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);
    }

这是console.log:

[$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。

0 个答案:

没有答案