Angular Owl Carousel doesn't slide horizontally, it slides vertically

Within my Angular project, I incorporated an Owl Carousel into the home-component.html file. Here is a snippet of the code:

<section>
  <div class="container">
    <h1 class="products-title">New Arrivals</h1>
    <div class="slider">
      <owl-carousel-o [options]="customOptions" class="owl-stage">
        <ng-template carouselSlide *ngFor="let product of products">
          <div class="card">
            <div class="card-content" [ngStyle]="{'background-color': isDarkTheme ? '#5eda5e' : '#3b5b2d'}">
              <img class="product-image" [src]="product.imgSrc" [alt]="product.name">
              <h2 class="product-title">{{ product.name | translate}}</h2>
              <p class="product-description">{{ product.description | translate}}</p>
              <p class="product-price">{{ product.price | currency:'USD':'symbol':'1.2-2' }}</p>
            </div>
          </div>
        </ng-template>
      </owl-carousel-o>
    </div>
  </div>
</section>

However, instead of displaying the cards horizontally as intended, they are being displayed vertically. Even when attempting to use display: flex and inspecting the

<owl-carousel-o></owl-carousel-o\>
, which actually has the owl-stage class, the issue persists despite applying display: flex.

I have been trying to align the cards containing product details and images horizontally. Below is the code snippet from app-component.ts:

import { Component, OnInit } from '@angular/core';
// Remaining content remains unchanged

Answer №1

Typically, it's not possible to directly alter the style of another component from your own component. So, here's a workaround:

  1. Firstly, check if the other component has the desired configuration. If not, move on to the next step.
  2. In such situations, we can utilize a powerful tool called ng-deep. Superpowers like this come with responsibility and control. By using ng-deep, we can tweak any component's style. But, be cautious as this may have implications across the application. To mitigate this risk, pair ng-deep with :host. The :host directive confines the ng-deep rules to only that specific component. This ensures that you manipulate styles solely within that component. In your home.component.css, you can customize your styles as follows:
:host {
  ::ng-deep .owl-stage {
    display: flex;
  }

  .product-image {
    width: 30%;
    border-radius: 5px;
  }

  .card {
    width: calc(33.33% - 20px);
    margin: 10px;
  }

  .card-content {
    padding: 20px;
    border-radius: 5px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  }
}

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

Why is there always a reference to the previous data every time I create a new component?

I am currently working on a component that retrieves data from a service through an event message: this.objectDetailsSubscription = this.eventService.subscribe( EventsChannels.OBJECT_DETAILS, semantic => { this.layer = this.layerSem ...

Using Angular for Sign in with Apple integration

I have been working on integrating Sign in with Apple into an Angular website. The implementation process begins with adding to the index.html file. Then I created a service named apple-login-service.ts using scriptjs. Here is the code for the apple but ...

Problem with Angular input field not updating after making an http request

After receiving a response from an http get request, I'm attempting to map the data with an input field but it's not working as expected. this.http.get<any>('https://localhost:9002/....../getEmail') .subscribe({ ...

Finding items in the database using their identification numbers

I have a scenario where I am accepting a list of IDs in my request, for example [1,2,3]. How can I use typeorm and querybuilder to retrieve only objects with these IDs from my database? I attempted the following: if(dto.customersIds){ Array.prototype. ...

Angular 6 - Share content easily on mobile devices (IOS, Android)

After reviewing this example detailing the use of Angular 5 for copying to clipboard, I encountered issues when trying to run it on the iPhone 6s. Is there a more comprehensive solution available? ...

Error message: "ExpressionChangedAfterItHasBeenCheckedError - encountered while using ngIf directive to hide/show a progress

My HTTP interceptor is set up to display a loading bar whenever an HTTP request is made: intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { const dataStorageService = this.injector.get(DataStorageService); ...

Error: The argument 'IParams' is not compatible with the parameter type 'IParams' in Typescript with NextJS14

I encountered an error in my code while using Prisma with Next.js 14 and TypeScript. The issue arises when trying to load product details via product ID. The error is captured in the screenshot below. Failed to compile. ./app/product/[productId]/page.tsx:1 ...

Angular 2 - Conceal Table Panel if there is no data in the table

I am using *ngFor to generate panels that contain tables. Each table uses *ngFor to create <td> elements for each item in a dataset. Sometimes the table will have empty rows. Is there a clever way to hide the panel when the table has no children? I ...

Is there a source where I can locate type definitions for Promise objects?

In the process of creating a straightforward class called Primrose, I am extending the global Promise object in order to include additional methods like resolve and reject. export class Primrose<Resolution> extends Promise<Resolution>{ priv ...

Event listener for scrolling in Angular Dart component

I am looking to implement a functionality where a "back to top" button appears once the user has scrolled the page by 500px. I have been trying to capture the scroll event in the main Div of my AppComponent. <div class="container" scrollable&g ...

Exploring the process of introducing a new property to an existing type using d.ts in Typescript

Within my src/router.ts file, I have the following code: export function resetRouter() { router.matcher = createRouter().matcher // Property 'matcher' does not exist on type 'VueRouter'. Did you mean 'match'? } In an ...

Navigating through the key type within a mapped structure

I am working with a mapped type in the following structure: type Mapped = { [Key in string]: Key }; My understanding is that this setup should only allow types where the key matches the value. However, I have found that both of the cases below are permitt ...

Changing the type of an object's property in TypeScript on the fly

I am working on a TypeScript function that is designed to dynamically modify the property of an object. Here is the function: const updateProperty = (value: any, key: keyof Type1, obj: Type1) => { obj[key] = value; } Below is the definition of "Typ ...

Add the onclick() functionality to a personalized Angular 4 directive

I'm facing an issue with accessing the style of a button in my directive. I want to add a margin-left property to the button using an onclick() function in the directive. However, it doesn't seem to be working. Strangely, setting the CSS from the ...

Tips for resolving the AngularFire migration error related to observables

Recently, I decided to upgrade a project that had been untouched for over a year. Originally built on Angular 10, I made the jump to Angular 12. However, the next step was upgrading AngularFire from v6 to v7, and it appears there is an issue with typings. ...

Encountering a problem when attempting to add ngrx to an Angular project

I'm currently in the process of setting up ngrx in my Angular application. After running the command ng add @ngrx/store@latest An error occurred with the following details: npm resolution error report 2022-07-07T20:36:16.089Z While resolving: [em ...

leveraging services in Angular 4's router system

Below is the route setup: export const routes: Routes = [ {path: '', redirectTo: '/login', pathMatch: 'full'}, {path: 'login', component: LoginComponent, canActivate: [dbs.ConfigGuard]}, {path: '**& ...

Differentiate input elements with custom styling

I'm experiencing an issue while trying to style a specific form field in Angular 7. The style doesn't seem to be applying properly. Below is my form structure: <ul> <li> <mat-form-field *ngIf="number"> <input ma ...

Updating the value in React context does not result in the value being updated

I am in the process of developing a simple routing system where users can either be authenticated or not. I have been using hooks to implement this functionality, but so far, it has not been as successful as I hoped for. authProvider.tsx import React, {Di ...

Navigate smoothly in Angular 4 with Spring Boot without the need for hash codes in the URL routing

Here is the scenario I am facing: I am currently using Spring Boot with Angular 4 I generate a build file using angular-cli and place it under the resource -- static folder. When I run my pom.xml, all the files in the static folder are copied to target ...