【问题标题】:I have simple question about ngx-pagination design in angular我有一个关于 ngx 分页设计的简单问题
【发布时间】:2022-01-15 08:22:27
【问题描述】:

我已经使用 ngx-pagination 在 Angular 8 应用程序中成功实现了对来自服务器的结果的分页。

这是模板:

<pagination-template #p="paginationApi"
                            (pageChange)="p2 = $event">

                            <div class="pagination-previous" [class.disabled]="p.isFirstPage()">
                                <a *ngIf="!p.isFirstPage()" (click)="p.previous()"> < </a>
                            </div>

                            <div *ngFor="let page of p.pages" [class.current]="p.getCurrent() === page.value">
                                <a (click)="p.setCurrent(page.value)" *ngIf="p.getCurrent() !== page.value">
                                    <span>{{ page.label }}</span>
                                </a>
                                <div *ngIf="p.getCurrent() === page.value">
                                    <span>{{ page.label }}</span>
                                </div>
                            </div>

                            <div class="pagination-next" [class.disabled]="p.isLastPage()">
                                <a *ngIf="!p.isLastPage()" (click)="p.next()"> > </a>
                            </div>
                    
                      </pagination-template>

我没有包含 .ts 文件中的详细信息,因为它与问题、分页无关 工作包括点击/选择不同的页面。 看一下附图,这样你就可以看到分页:

从图片中可以看出,问题只是控件的设计,没有应用css 以及垂直显示的页面。

从教程中我找到了添加到我的 styles.css 文件中的 css 元素,如下所示:

 .custom-pagination .page-number{
        display: inline-block;
        /* padding: 5px 12px; */
        background: #afffe6;
        margin: 0px 4px;
        border-radius: 25px;
    }
    
    .page-number.current{
        background: #ffffff!important;
        border: 2px solid #458873;
    }
    
    .page-number span{
        display: block;
        width: 28px;
        height: 28px;
        font-size: 18px;
        cursor: pointer;
    }
    
    .pagination-previous,.pagination-next{
        display: inline-block;
        font-weight: bold;
    }

这种 css 样式没有影响。假设样式是正确的(我可以稍后更改它们 由 css 开发人员提供)您可以使用

谢谢!

【问题讨论】:

    标签: css angular ngx-pagination


    【解决方案1】:

    您可以尝试覆盖 ngx-paginator 样式

    在使用该分页器的 HTML 的 scss 文件中,尝试如下操作:

    :host ::ng-deep {
    
      .custom-pagination .page-number{
            display: inline-block;
            /* padding: 5px 12px; */
            background: #afffe6;
            margin: 0px 4px;
            border-radius: 25px;
        }
        
        .page-number.current{
            background: #ffffff!important;
            border: 2px solid #458873;
        }
        
        .page-number span{
            display: block;
            width: 28px;
            height: 28px;
            font-size: 18px;
            cursor: pointer;
        }
        
        .pagination-previous,.pagination-next{
            display: inline-block;
            font-weight: bold;
        }
    
    }
    

    这只是一个例子。您必须在浏览器中选择 paginator 元素并检查 angular 对其“命名”的确切方式(以便知道您必须在 scss 中使用的确切名称以覆盖特定元素)。

    【讨论】:

    • 我不使用 scss,应用程序使用基本 css,我可能还需要答案,包括在哪里应用 css 样式 class=""
    猜你喜欢
    • 2023-01-31
    • 2011-03-20
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 2011-03-06
    • 2012-05-09
    • 1970-01-01
    • 2011-07-19
    相关资源
    最近更新 更多