按钮组中的Bootstrap角度响应度问题

问题描述 投票:0回答:1

我是前端开发的新手,我希望能够完全堆叠,我使用Jhipster,角度和自举来进行自学。

我成功安装了bootswatch主题(脉冲),经过一些工作,我试图创建一个卡列表来呈现一些数据。

不幸的是,我的工作缺乏响应性,如下图平板电脑模式所示

students pane

如你所见,还有很多工作要做,我不知道该怎么办才能解决这个问题

所以我只询问如何解决我的卡中的按钮问题,这可能会让我理解并掌握单独处理其他问题(菜单和过滤器)

下面我提供了我认为暗示的所有代码:

主app模板

<jhi-page-ribbon></jhi-page-ribbon>
<div>
    <router-outlet name="navbar"></router-outlet>
</div>
<div class="container-fluid">
    <div class="container-fluid mt-4">
        <router-outlet></router-outlet>
        <router-outlet name="popup"></router-outlet>
    </div>
    <jhi-footer></jhi-footer>
</div>

卡片代码片段在我的候选人模板中

1个全局模板:所有代码

<div>
    <h2 id="page-heading">
        <span jhiTranslate="autoEcoleV01App.candidat.home.title">Candidats</span>
        <button id="jh-create-entity" class="btn btn-primary float-right jh-create-entity create-candidat"
            [routerLink]="['/candidat/new']">
            <fa-icon [icon]="'plus'"></fa-icon>
            <span jhiTranslate="autoEcoleV01App.candidat.home.createLabel">
                Create new Candidat
            </span>
        </button>
    </h2>
    <jhi-alert></jhi-alert>
    <br />
    <div jhiSort [(predicate)]="predicate" [(ascending)]="reverse" [callback]="transition.bind(this)">
        <div class="row mb-4 ml-1">
            <input type="search" class="form-control col-sm-8 " autocomplete="off" placeholder="{{'autoEcoleV01App.constants.search' | translate}}"
                [(ngModel)]="searchValue" />
            <div class="btn-group col-sm-4">
                <button class="btn btn-sm float-left btn-outline-secondary col" jhiSortBy="nom">
                    <span jhiTranslate="autoEcoleV01App.candidat.nom">Nom</span>
                    <fa-icon [icon]="'sort'"></fa-icon>
                </button>
                <button class="btn btn-sm float-left btn-outline-secondary col" jhiSortBy="prenom">
                    <span jhiTranslate="autoEcoleV01App.candidat.prenom">Prenom</span>
                    <fa-icon [icon]="'sort'"></fa-icon>
                </button>
                <button class="btn btn-sm float-left btn-outline-secondary col" jhiSortBy="nid">
                    <span jhiTranslate="autoEcoleV01App.candidat.nid">Nid</span>
                    <fa-icon [icon]="'sort'"></fa-icon>
                </button>
            </div>
        </div>
        <div class="row">
            <div *ngFor="let candidat of (candidats | filterBy: ['nom','prenom','mere','pere','telephone','nid']: searchValue) ;trackBy: trackId"
                class="col-sm-3 mb-4">
                <div class="card card-focusable" style="min-height: 100%;">
                    <a *ngIf="candidat.photo" (click)="openFile(candidat.photoContentType, candidat.photo)">
                        <img [src]="'data:' + candidat.photoContentType + ';base64,' + candidat.photo"
                            style="max-height: 360px;  max-width: 100%;"
                            class="card-img-top " alt="candidat image" />
                    </a>
                    <div class="card-body ">
                        <h4 class="card-title">{{candidat.nom}} {{candidat.prenom}}</h4>
                        <p class="card-text ml-1">
                            <span jhiTranslate="autoEcoleV01App.candidat.dateInscription">Date Inscription  </span>: {{candidat.dateInscription | date:'mediumDate'}}
                            <br >
                            <span jhiTranslate="autoEcoleV01App.candidat.telephone">Téléphone  </span>: {{candidat.telephone}}
                         </p>
                        <div class="text-right">
                            <div class="btn-group flex-btn-group-container">
                                <button type="submit" [routerLink]="['/candidat', candidat.id, 'view' ]"
                                    class="btn btn-info btn-sm">
                                    <fa-icon [icon]="'eye'"></fa-icon>
                                    <span class="d-none d-md-inline" jhiTranslate="entity.action.view">View</span>
                                </button>
                                <button type="submit" [routerLink]="['/candidat', candidat.id, 'edit']"
                                    class="btn btn-primary btn-sm">
                                    <fa-icon [icon]="'pencil-alt'"></fa-icon>
                                    <span class="d-none d-md-inline" jhiTranslate="entity.action.edit">Edit</span>
                                </button>
                                <button type="submit"
                                    [routerLink]="['/', 'candidat', { outlets: { popup: candidat.id + '/delete'} }]"
                                    replaceUrl="true" queryParamsHandling="merge" class="btn btn-danger btn-sm">
                                    <fa-icon [icon]="'times'"></fa-icon>
                                    <span class="d-none d-md-inline" jhiTranslate="entity.action.delete">Delete</span>
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>

    </div>
 </div>

2只有卡片代码,便于阅读

<div class="card-body ">
   <h4 class="card-title">{{candidat.nom}} {{candidat.prenom}}</h4>
   <p class="card-text ml-1">
      <span jhiTranslate="autoEcoleV01App.candidat.dateInscription">Date Inscription  </span>: {{candidat.dateInscription | date:'mediumDate'}}
      <br >
      <span jhiTranslate="autoEcoleV01App.candidat.telephone">Téléphone  </span>: {{candidat.telephone}}
   </p>
   <div class="text-right">
      <div class="btn-group flex-btn-group-container">
         <button type="submit" [routerLink]="['/candidat', candidat.id, 'view' ]"
            class="btn btn-info btn-sm">
            <fa-icon [icon]="'eye'"></fa-icon>
            <span class="d-none d-md-inline" jhiTranslate="entity.action.view">View</span>
         </button>
         <button type="submit" [routerLink]="['/candidat', candidat.id, 'edit']"
            class="btn btn-primary btn-sm">
            <fa-icon [icon]="'pencil-alt'"></fa-icon>
            <span class="d-none d-md-inline" jhiTranslate="entity.action.edit">Edit</span>
         </button>
         <button type="submit"
            [routerLink]="['/', 'candidat', { outlets: { popup: candidat.id + '/delete'} }]"
            replaceUrl="true" queryParamsHandling="merge" class="btn btn-danger btn-sm">
            <fa-icon [icon]="'times'"></fa-icon>
            <span class="d-none d-md-inline" jhiTranslate="entity.action.delete">Delete</span>
         </button>
      </div>
   </div>
</div>
angular bootstrap-4 jhipster responsive bootswatch
1个回答
0
投票

感谢JB Nizet评论,我是在直路上做的,所以我搜索了一种方法,以确保有空间,我的答案是断点

这是我做的:

这是我对解决方案的实现

在我的全局应用程序模块app.module.ts中导入模块以在所有组件中使用

import { LayoutModule } from '@angular/cdk/layout';
@NgModule({
    imports: [...
              LayoutModule,
              ...])

在我的BreakpointService中使用candidat.component.ts

import { BreakpointObserver, BreakpointState, Breakpoints } from '@angular/cdk/layout';

@Component({
    selector: 'jhi-candidat',
    templateUrl: './candidat.component.html'
})
export class CandidatComponent implements OnInit, OnDestroy {
  someVars: any;
  small: any;
  medium: any;
  large: any;

  constructor(
    protected someServices: MyServices,
    public breakpointObserver: BreakpointObserver
  ){}

  ngOnInit() {
    this.someLogic();
    this.breakpointObserver
            .observe(['(max-width: 425px)'])
            .subscribe((state: BreakpointState) => {
                if (state.matches) {
                    this.small = true;
                    this.medium = false;
                    this.large = false;
                }
                console.log('Small screen event');
            });
    this.breakpointObserver
            .observe(['(max-width: 1025px)', '(min-width: 426px)'])
            .subscribe((state: BreakpointState) => {
                if (state.matches) {
                    this.small = false;
                    this.medium = true;
                    this.large = false;
                }
                console.log('Medium screen event');
            });
    this.breakpointObserver
            .observe(['(min-width: 1025px)'])
            .subscribe((state: BreakpointState) => {
                if (state.matches) {
                    this.small = false;
                    this.medium = false;
                    this.large = true;
                }
                console.log('Large screen event');
            });
    }

    cardsStyleClasses() {
        return {
            'mb-4': true,
            'col-sm-1': this.small,
            'col-sm-4': this.medium,
            'col-sm-3': this.large
        };
    }
} 

最后在我的模板中使用ngClass

[ngClass]="cardsStyleClasses()"
© www.soinside.com 2019 - 2024. All rights reserved.