0

我有这个由分页元素生成的 HTML:

<ul class="pagination ng-isolate-scope ng-valid" ng-change="gestTrt.pageChanged()" ng-model="gestTrt.currentPage" items-per-page="1" total-items="4" direction-links="false" aria-invalid="false">
  <li class="pagination-page ng-scope" ng-class="{active: page.active,disabled: ngDisabled&&!page.active}" ng-repeat="page in pages track by $index" style="">
  <li class="pagination-page ng-scope" ng-class="{active: page.active,disabled: ngDisabled&&!page.active}" ng-repeat="page in pages track by $index" style="">
  <li class="pagination-page ng-scope" ng-class="{active: page.active,disabled: ngDisabled&&!page.active}" ng-repeat="page in pages track by $index" style="">
  <li class="pagination-page ng-scope active" ng-class="{active: page.active,disabled: ngDisabled&&!page.active}" ng-repeat="page in pages track by $index" style="">
</ul>

我想选择每个元素来添加一个类。我试过了:

angular.forEach(angular.element(document.querySelector(".pagination")).children(), function(value, key){
       value.addClass('active');

但我得到“错误:value.addClass 不是函数”

4

2 回答 2

1

UI分页的源代码在这里:

https://github.com/angular-ui/bootstrap/blob/master/src/pagination/pagination.js

AngularJS 使用angular.element. 相关文档在这里:

https://docs.angularjs.org/api/ng/function/angular.element

在您查看完这些内容后,请返回您的 HTML 样本并提出更具体的问题。

更新

ng-class使用指令向元素添加类更容易。

有关该ng-class指令的更多信息,请参阅AngularJS ngClass API 参考

于 2015-11-25T15:27:06.397 回答
0

我使用 angular.element(value); 解决了

于 2015-11-26T10:34:09.397 回答