The custom Ionic slides component {Slides} will only update the reference of the last created slide component

Desired outcome: When incorporating multiple ionic slides components into a page, the ability to reference and adjust their properties based on screen size is expected.

Current situation: Upon adding multiple ionic slides components to a page and attempting to modify their properties based on screen size, only the last created slide component actually reflects the new settings.

MovieSliderComponent.html

<ion-slides #Slides class="slides" *ngIf="movies.length > 0" centeredSlides="true" loop="true" slidesPerView="3">

A reference to slides is included in the HTML code.

MovieSliderComponent.ts

@ViewChild('Slides') slider: Slides;

The reference is applied to a variable.

Home.html

<movie-slider #Slider id="nowPlaying" *ngIf="mdata.inTheatres.length > 0" [movies]="mdata.inTheatres">

<movie-slider #Slider id="nowPlayingNearYou" *ngIf="mdata.nearbyShowings.length > 0" [movies]="mdata.nearbyShowings">

<movie-slider #Slider id="genreSuggestions" *ngIf="mdata.suggestedByGenre.length > 0" [movies]="mdata.suggestedByGenre" [showGenres]="true">

The component is included in the page HTML three times.

Home.ts

@ViewChildren('Slider') Slides: MovieSliderComponent[];

Each of the sliders is referenced in a variable.

setSlidesPerView() {

 if(this.platform.width() >= 1200) {
   this.Slides.forEach((slider) => slider.slider.slidesPerView = 5);
   console.log(this.platform.width());
 }

 else if(this.platform.width() >= 319 && this.platform.width() < 1200) {
   this.Slides.forEach((slider) => slider.slider.slidesPerView = 3);
 }

 else if(this.platform.width() < 319) {
   this.Slides.forEach((slider) => slider.slider.slidesPerView = 1);
 }

 this.cd.detectChanges();
}

An attempt is made to alter the slidesPerView option for each slider, but only the last slide with slide-id-2 gets updated.

Original issue link @ionic-team/ionic-v3 https://github.com/ionic-team/ionic-v3/issues/990

Answer №1

To resolve this issue, I implemented a solution by executing slides.resize and slides.update on every individual instance of slides.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a new implementation of "ComponentFactoryResolver deprecated" with missing attributes?

Since Angular 13, the usage of ComponentFactoryResolver has been deprecated. Finding a suitable replacement is proving to be a challenge as the old rootSelectorOrNode parameter is no longer available in the new solution. I have a requirement to dynamicall ...

Transferring session id across various devices using PHP

Here's the scenario: I have two users accessing different pages on separate devices - one user is on page 1 and the other is on page 2. My goal is to implement PHP forms on page 1 that can dynamically change the content displayed on the second user& ...

Understanding the Functions of Angular Providers and Implementing Them

Just starting out with Angular and following a tutorial from this video. I decided to experiment by adding providers :[EmployeeService] to both employee-list.component.ts and empployee.component.ts within the @component section. However, this led to an err ...

What is the best method for distinguishing between regular users and admin users in the layouts of an Angular application?

Recently, I've received details about a new project I'll be working on. It's an administrative application that will have multiple users with various roles and permissions to manage. Option 1: Develop a Lazy Loaded module for each user, inc ...

Retrieving the latest entry from the MySQL database

I am encountering an issue with a code that involves fetching data from MySQL into an array. I have a form with color and size select boxes, and when an onclick javascript function is triggered it creates two additional select boxes. I have successfully re ...

Streamline Access to Zimbra Server Automatically

Currently, I am creating a webpage with a login feature at www.newpage.com. Here is the code snippet for reference: <form name="login"> Username<input type="text" name="userid"/> Password<input type="password" name="pswrd"/> <input ty ...

Implementing Typescript with React: Assigning event.target.name to state

I am facing an issue with a React state that has specific named keys defined in an interface... Despite trying a potential solution based on the state keys, I am still encountering an error... { [x: string]: string; }' provides no match for the sign ...

Tips on effectively organizing information retrieved from an XML file?

I would like to organize the data in ascending order based on the DATE after making this ajax call function parseXML(xml){ var weatherArray = []; var weatherElement = xml.getElementsByTagName("forecast")[0]; weatherArray.queryTime = weatherEl ...

What is the best way to extract keys from a hash in Ruby using a Javascript string?

I am currently developing a command line tool using Ruby that is designed to parse JSON data from diverse sources and perform certain operations on the retrieved information. To make it user-friendly, I have incorporated a feature where users can configure ...

Click on the window.location.href to redirect with multiple input values

I am facing a challenge with my checkboxes (from the blog label) and the code I have been using to load selected labels. However, this code seems to only work for one label. Despite multiple attempts, I have found that it only functions properly with one ...

Having trouble with res.redirect not working after the page has been rendered with data?

I have a basic forget password feature set up, where users can request a password change and receive an email with a token. Clicking the link in the email will redirect them to a page where they can input their new password. When I click on the email link ...

jQuery UI Slider is malfunctioning (code example included)

I've implemented a jQuery UI slider on my website, and it's functioning quite well. You can check out the slider HERE. However, I've noticed that when I click on 'back to the top', the page smoothly scrolls up. But when I use the ...

elementToBeClickable is not supported by webdriverio

I am having some trouble with the 'waitForEnabled' function as it does not seem to behave like Webdriver's elementToBeClickable. Is there anyone who can provide some guidance on how to use this API effectively? ...

Working with JSON in the Angular frontend

Looking for assistance to display my JSON data in an Angular frontend in a tree-like structure or an extension. Here is my backend JSON, it consists of a Buildings array grouped by campuses for relational MongoDB databases. [ { "_id": "campus4", "bui ...

What is a universal method to express "not yet interacted with" in Vue?

When I have an input field, I want to check the content before submitting it. Depending on whether the input is correct or incorrect, I apply a specific class for user feedback: new Vue({ el: "#app", data: { input: "" }, methods: { getCl ...

Can anyone provide guidance on incorporating lodash into an Ionic 2 project?

Recently, I began diving into a new project that involves Ionic 2. TypeScript is still fairly new to me, and I've been brainstorming ways to integrate lodash into my project. Have any of you tackled this before and can offer guidance on how to achiev ...

Creating a TypeScript declaration file for a singular module

Consider the following directory structure: src/ ├── foo.ts ├── bar.ts ├── baz.ts ├── index.ts If foo.ts, bar.ts, and baz.ts each export a default class or object, for example in foo.ts: export default class Foo { x = 2; } I ...

What is the best way to activate a component within Angular 2 that triggers the display of another component through method invocation?

I have created a popup component that can be shown and hidden by calling specific methods that manipulate the back and front variables associated with the class. hide() { this.back = this.back.replace(/[ ]?shown/, ""); this.front = this.front.replace( ...

Is the state variable not being properly set by using React's setState within the useCallback() hook?

Within a React FunctionComponent, I have code that follows this pattern: const MyComponent: React.FunctionComponent<ISomeInterface> = ({ someArray, someFunction }) => { const [someStateObjVar, setSomeStateObjVar] = React.useState({}); const [ ...

What is the process for importing a JSON5 file in Typescript, just like you would with a regular JSON file?

I am looking to import a JSON5 file into a JavaScript object similar to how one can import a JSON file using [import config from '../config.json']. When hovering over, this message is displayed but it's clearly visible. Cannot find module & ...