Angular-bootstrap 分页 - 在 'scope' 中没有变量
Angular-bootstrap pagination - not getting variable in 'scope'
HTML
<table ng-show="ecu.dtcs">
<tbody>
<tr>
<td colspan="4">
<uib-accordion close-others="true">
<uib-accordion-group ng-repeat="dtc in dtcList track by $index">
...
</uib-accordion-group>
</uib-accordion>
</td>
</tr>
</tbody>
</table>
<uib-pagination
total-items="{{ totalItems }}"
ng-model="{{ currentPage }}"
items-per-page="{{ itemsPerPage }}"
boundary-link-numbers="true"
ng-change="setPagingData(currentPage)">
</uib-pagination>
JS(指令)
link: function (scope) {
scope.showEcuDetails = function (ecu) {
// For pagination
scope.itemsPerPage = 20;
scope.totalItems = ecu.dtcs.length;
scope.currentPage = 1;
scope.setPagingData = function(currentPage) {
var start = (currentPage - 1) * scope.itemsPerPage,
end = currentPage * scope.itemsPerPage;
scope.dtcList = ecu.dtcs.slice(start, end);
};
scope.setPagingData(scope.currentPage);
};
}
ecu.dtcs
: 保存我想要的所有数据
dtcList
:保存sliced
列表每20个元素
我使用了 Angular-Bootstrap documentation and have also referenced this (除了使用 ng-change
来更改列表而不是范围上的 $watch
)
我已经彻底调试了应用程序,我可以看到 dtcList
正在填充前 20 个元素。然而,进入HTML,没有任何显示
我也试过写一个.filter
(如图)但是因为变量是在指令范围内设置的,而不是控制器,我的过滤器看不到变量
N.B: 对于分页设置,为了引用范围变量(即 totalItems
),我使用了 Angular 表达式,例如显示在此问题中以及文档中的基本字符串(即 "totalItems"
)
我认为我目前编写的概念和方式应该可行,只是 HTML 出于某种原因看不到 dtcList
编辑
了解这是在 angular-ui-bootstrap 模式中可能会有所帮助。在 setPagingData()
的函数调用下面,我有这个:
$uibModal.open({
templateUrl: "ecuDialog.html",
size: "lg",
windowClass: "modalDialogs networkTest__largeContentDialog",
scope: scope
});
templateUrl
是我在这个问题的 HTML 部分写的.我想过这是否是问题所在,但我的同事向我保证这不会以任何方式影响结果。
编辑 2
不幸的是,我们的 1 位专门研究 AngularJS 的同事查看了代码和文档,但没有发现其中的任何错误。可能是 Angular 错误,还是它不喜欢 angular-ui-bootstrap
中的多个元素的组合?
我合并的东西是:
ui-modal
ui-accordion
ui-pagination
解法:
我的代码是正确的。我的同事尝试了一下,只是把我写的代码放到了另一个指令中。我们都不确定为什么会这样,也许 Angular 不喜欢拥挤的指令?
HTML
<table ng-show="ecu.dtcs">
<tbody>
<tr>
<td colspan="4">
<uib-accordion close-others="true">
<uib-accordion-group ng-repeat="dtc in dtcList track by $index">
...
</uib-accordion-group>
</uib-accordion>
</td>
</tr>
</tbody>
</table>
<uib-pagination
total-items="{{ totalItems }}"
ng-model="{{ currentPage }}"
items-per-page="{{ itemsPerPage }}"
boundary-link-numbers="true"
ng-change="setPagingData(currentPage)">
</uib-pagination>
JS(指令)
link: function (scope) {
scope.showEcuDetails = function (ecu) {
// For pagination
scope.itemsPerPage = 20;
scope.totalItems = ecu.dtcs.length;
scope.currentPage = 1;
scope.setPagingData = function(currentPage) {
var start = (currentPage - 1) * scope.itemsPerPage,
end = currentPage * scope.itemsPerPage;
scope.dtcList = ecu.dtcs.slice(start, end);
};
scope.setPagingData(scope.currentPage);
};
}
ecu.dtcs
: 保存我想要的所有数据dtcList
:保存sliced
列表每20个元素
我使用了 Angular-Bootstrap documentation and have also referenced this ng-change
来更改列表而不是范围上的 $watch
)
我已经彻底调试了应用程序,我可以看到 dtcList
正在填充前 20 个元素。然而,进入HTML,没有任何显示
我也试过写一个.filter
(如图
N.B: 对于分页设置,为了引用范围变量(即 totalItems
),我使用了 Angular 表达式,例如显示在此问题中以及文档中的基本字符串(即 "totalItems"
)
我认为我目前编写的概念和方式应该可行,只是 HTML 出于某种原因看不到 dtcList
编辑
了解这是在 angular-ui-bootstrap 模式中可能会有所帮助。在 setPagingData()
的函数调用下面,我有这个:
$uibModal.open({
templateUrl: "ecuDialog.html",
size: "lg",
windowClass: "modalDialogs networkTest__largeContentDialog",
scope: scope
});
templateUrl
是我在这个问题的 HTML 部分写的.我想过这是否是问题所在,但我的同事向我保证这不会以任何方式影响结果。
编辑 2
不幸的是,我们的 1 位专门研究 AngularJS 的同事查看了代码和文档,但没有发现其中的任何错误。可能是 Angular 错误,还是它不喜欢 angular-ui-bootstrap
中的多个元素的组合?
我合并的东西是:
ui-modal
ui-accordion
ui-pagination
解法:
我的代码是正确的。我的同事尝试了一下,只是把我写的代码放到了另一个指令中。我们都不确定为什么会这样,也许 Angular 不喜欢拥挤的指令?