为什么我的 bootstrap carrousel 无法在 Angular 17 SSR 上加载?

问题描述 投票:0回答:1
angular bootstrap-5
1个回答
0
投票

我认为您没有任何理由应该使用

afterRender
函数。

可以在

getCarrusel
生命周期中调用
ngOnInit
函数。

ngOnInit() {
  this.getCarrusel();
}

如果您热衷于使用

afterRender
,您应该使用 角度信号

slidesSignal = signal([] as Carrusel[]);

getCarrusel() {
  this.apiService.getCarrusel().subscribe((data: Carrusel[]) => {
    this.slides = data;
    this.slidesSignal.set(this.slides);
    console.log(this.slides);
  });
}
@for (slide of slidesSignal(); track slide; let i = $index) {
  ...
}

演示@StackBlitz

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