angular自定義指令 repeat 循環結束事件;limitTo限制循環長度、限定開始位置

1.獲取repeat循環結束:html

自定義指令:spa

.directive('repeatFinish', function () {
        return {
            link: function (scope, element, attrs) {
                if (scope.$last) {                   // 這個判斷意味着最後一個 OK
                    scope.$eval(attrs.repeatFinish);    // 執行綁定的表達式
                }
            }
        }
})

html:code

<li  ng-repeat="item in shortCutMenu.list" repeat-finish="repeatEnd($index)"></li>

controller:htm

 $scope.repeatEnd = function (idx) {
            alert(idx);
};

 

2.limitTo過濾,指定循環開始位置,循環長度blog

ng-repeat="bMsg in buyMsg|limitTo:20"  <!--限制循環長度,20條-->
ng-repeat="sMsg in sellMsg|limitTo:20:5"  <!--20是長度限制,5是指定循環開始下標(第一條下標是0)-->
相關文章
相關標籤/搜索