简体   繁体   English

NGX-Bootstrap/Angular - 分页 - 当我的屏幕视图(宽度)发生变化时无法更改 maxSize 输入

[英]NGX-Bootstrap/Angular - Pagination - cannot change the maxSize input when my screen view (width) is changing

I am using the Pagination from Valor Software (click to access) .我正在使用Valor Software 的分页(点击访问)

I want to change the maxSize input when my screen width is changing, like in the following example: Click to see example .我想在屏幕宽度发生变化时更改 maxSize 输入,如下例所示: 单击查看示例

Seems that the maxSize is only changing by refreshing the page and not when the width is changing.似乎 maxSize 仅通过刷新页面而不是在宽度更改时更改。 Noticed that the input boundaryLinks can be updated when the width is changing.注意到输入的边界链接可以在宽度发生变化时更新。

For the width I set a HostListener to listen for the window:resize event like in the following example:对于宽度,我设置了一个 HostListener 来监听 window:resize 事件,如下例所示:

@HostListener('window:resize', ['$event'])  onWindowResize() {
  this.getScreenWidthOnResize = window.innerWidth;
  if(this.getScreenWidthOnResize <= 1050) {
   this.maxSize = 3;
  } else {
   this.maxSize = 10;
  }
  console.log(this.getScreenWidthOnResize);
}

To change the maxSize.更改 maxSize。 In the html page I have the following:在 html 页面中,我有以下内容:

 <pagination                                                
  [boundaryLinks]="showBoundaryLinks=true"
  [totalItems]="totalItems=30"
  [itemsPerPage]="itemsPerPage=5"
  [(ngModel)]="currentPage=6"
  (pageChanged)="pageChanged($event)"
  [maxSize] = "maxSize=default 10, but when width gets smaller, change it to 3, meaning that will be visible only 3 pages that the user can choose"
  [rotate] = "true"
  ></pagination>

Just the regular I would say.只是我会说的常规。 Any idea why the maxSize is not changing when the width is changing?知道为什么当宽度变化时 maxSize 没有变化吗?

Or something that helps me to change the limits on smaller screens.或者帮助我改变小屏幕限制的东西。

Looks like ngx-bootstrap (vs @ng-bootstrap/ng-bootstrap ) implementation of pagination component doesn't support dynamic changes of maxSize .看起来分页组件的ngx-bootstrap (与@ng-bootstrap/ng-bootstrap相比)实现不支持maxSize的动态更改。

Here's a workaround:这是一个解决方法:

import { Component, HostListener, ViewChild } from '@angular/core';
import { PaginationComponent } from 'ngx-bootstrap/pagination';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
})
export class AppComponent {
  maxSize = 3;

  @ViewChild(PaginationComponent) paginationComp!: PaginationComponent;

  @HostListener('window:resize', ['$event'])  onWindowResize() {
    const newMaxSize = window.innerWidth <= 1050 ? 3 : 10;
    if (this.paginationComp.maxSize !== newMaxSize) {
      this.paginationComp.maxSize = newMaxSize;
      this.paginationComp.selectPage(this.paginationComp.page)
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM