0

In my .ts file inside the class itself, I set this class with different properties, like slides in the virtual object.

Question - I want to access and add more slides in my .ts file in both the ngOnInit and in some event, but I can't seem to figure out how to do it.

When I try and access

    this.memberSwiperConfig.virtual.slides

slides doesn't exist. So I get a red underline. I tried making it nullable but that didn't work.

    memberSwiperConfig: SwiperConfigInterface = {
      virtual: {
        slides: (function() {
          const slides = [];
          for (let i = 0; i < 600; i += 1) {
            slides.push(
              '<img src="https://picsum.photos/600/600/?image=' +
              (i + 1) +
              '"/><p>' +
              (i + 1) +
              "</p>"
            );
          }
          return slides;
        })()
      },
      preloadImages: false,
      lazy: true,
      slidesPerView: 1,
      spaceBetween: 10,
      watchOverflow: true,
      navigation: true,
      grabCursor: true,
      breakpoints: {
        568: {
          slidesPerView: 2,
          spaceBetween: 10,
        },
        768: {
          slidesPerView: 2,
          spaceBetween: 10,
        },
        1024: {
          slidesPerView: 2,
          spaceBetween: 10,
        }
      }
    }
Sergey Panteleev
  • 122
  • 1
  • 1
  • 10
chuckd
  • 13,460
  • 29
  • 152
  • 331
  • `this.memberSwiperConfig.virtual.slides()` ? it's a function – Eliseo Jun 07 '22 at 08:39
  • Slides is either a bool | VirtualOptions object. So in the config, if I set it to what you see above and create slides as an array, that is what the value is, so trying to call a method on it won't work. – chuckd Jun 07 '22 at 18:26

0 Answers0