动态更改ngx-bootstrap(角度8)的Carousel组件上每个幻灯片的项目

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

我使用ngx-bootstrap创建了一个正常工作的caroucel,它工作正常,但现在我试图使[itemsPerSlide]随页面宽度动态变化。我尝试在组件中使用@HostListener('window:resize', ['$event']) onResize(event) {...,但是即使“数字”值根据页面宽度而改变,每个幻灯片的项目在html上也不会改变,

<!--<HTML>--->
<carousel [itemsPerSlide]="number">
  <slide *ngFor...>
    ....
  </slide>
</carousel>
<!--COMPONENT-->
@HostListener('window:resize', ['$event']) onResize(event) {
    this.width = event.target.innerWidth;
   if(this.width <= 480 /*small*/){
      this.number = 1
   }...

任何建议都会有所帮助。

angular ngx-bootstrap
1个回答
0
投票

我想念有关您问题的更多信息,但是我在Stackblitz上举了一个解决该问题的示例。我希望它有用,click here

尽管我认为限制项目的最佳方法是使用CSS,使用媒体查询和选择器:not(:first-child) { display: none }

© www.soinside.com 2019 - 2024. All rights reserved.