ng-click函数执行顺序错误

时间:2015-10-30 15:34:14

标签: angularjs

我有一个包含多个页面的表格和一个滚动页面的导航。我的ng-click" refill_checkboxes"应在下一页渲染后执行,但始终先执行。我怎么能以正确的方式做到这一点?

<table>
    <thead>
        <th>Term</th>
        <th class="check">Check</th>
    </thead>
    <tr ng-repeat="term in data | slice:panel.offset:panel.offset+panel.size" ng-show="showMeta(term)" ng-attr-id="{{term.id}}">
        <td>{{term.label}}</td>
        <td><input type="checkbox" ng-click="switch_TermsCheck(term,this)" ng-attr-id="{{term.id}}" value="term" /></td>
    </tr>
</table>

<div>
    <i ng-click="panel.offset = (panel.offset + panel.size);refill_checkboxes(this);" ng-show="data.length > panel.offset+panel.size" class='icon-arrow-right pointer'></i>
</div>

1 个答案:

答案 0 :(得分:1)

Javascript是单线程的,据我所知,ng-click以正确的顺序执行。您可以通过这种方式将函数调用移到下一个滴答:

创建一个函数:

//don't forget to include $timeout in your controller
$scope.goNext = function(that) {
    $scope.panel.offset = ($scope.panel.offset + $scope.panel.size);
    $timeout(function() {
        refill_checkboxes(that)
    }, 0);
};

<i ng-click="go
Next(this)" ng-show="data.length > panel.offset+panel.size" class='icon-arrow-right pointer'></i>