如何在ng-repeat
中设置动态限制?如果窗口宽度小于750 px而不是设置限制为1,我想设置限制。
这是我的控制器功能:
$scope.$watch('window.innerWidth', function() {
$scope.wsizewindow = window.innerWidth;
if($scope.wsizewindow < 750) {
$scope.limit = 0;
} else {
}
console.log($scope.wsizewindow);
});
这是我的HTML:
<flex-slider slider-id=""
flex-slide="responsibilities in roles.responsibilities track by $index | limitTo: limit" animation="slide"
animation-loop="false" item-width="350" item-margin="1" keyboard="false"
as-nav-for="#slider" slideshow="false" control-nav="false">
<li class="col-sm-3" ng-if="responsibilities.responsibilityName!=''">
<div class="new-box" ng-if="$index!=roles.responsibilities.length-1">
<div class="panel-heading1">Responsibility</div>
<div class="col-xs-12 col-sm-12">
<div class="strike" >
<span >{{responsibilities.responsibilityName}}</span>
</div>
</div>
<div class="col-xs-12 col-sm-12 box">
<div class="form-group list" mb-scrollbar="scrollbar('vertical', true)">
<div class="panel panel-default" style="cursor: pointer;" ng-click="invokeReviewProcess(departments,roles,responsibilities,processes,isCompAdmin);" ng-repeat="processes in responsibilities.processes">
<span class="id">{{processes.name}}</span>
</div>
</div>
<div align="center" id="addProcessLink" ng-if="isAdmin === true && isGraph">
<a class="primary-link" ng-click="addProcess(departments.id,roles.id,responsibilities.id)" href="#"> Add a Process</a>
</div>
</div>
</div>
</li>
</flex-slider>
我想在这里设置限制:
responsibilities in roles.responsibilities track by $index | limitTo: limit.
给我一些建议。我是AngularJs的新手。谢谢。
答案 0 :(得分:1)
使用控制器中定义的功能:
responsibilities in roles.responsibilities track by $index | limitTo: (setLimit())
在您的控制器中:
$scope.setLimit = function() {
//check if window width less than 750, if yes, return 1 else some other limit
}