What is the best way to customize the active and centered slide in ngx owl carousel within an Angular environment?

I've been spending some time trying to figure out how to style the .active.center slide that was created by the Ngx Owl Carousel structural directive.

In the image below, you can see a .owl-item.active.center that was generated by the

<ng-template carouselSlide>
part of the template. I'm struggling to access it directly using .owl-item.active.center.

https://i.sstatic.net/EihsG.png

Here is what I have tried:

Template:

<owl-carousel-o [options]="testimonialsCarousel" (change)="getData($event)" class="w-100">

  <ng-container *ngFor="let testimonial of testimonials">

    <ng-template carouselSlide>

      <article #testimonialarticle class="d-flex flex-column align-items-center
      shadow p-4 m-3 text-center testing-class">

        <figure><img class="img-circle" [src]="testimonial.avatar" [alt]="testimonial.avatarAlt"></figure>

        <p>{{testimonial.text}}</p>
        <p>{{testimonial.author}}</p>

      </article>

    </ng-template>

  </ng-container>
</owl-carousel-o>

My TypeScript:

// Carousel Class that uses OnInit
export class RowClientsComponent implements OnInit {
 
  testimonialsCarousel: OwlOptions = {
    center: true,
    dots: true,
    autoplay: false,
    loop: true,
    autoplayTimeout: 5000,
    autoplaySpeed: 1000,
    smartSpeed: 1000,
    autoplayHoverPause: true,
    autoWidth: true,
    items: 3
  }

  testimonials: Testimonial[] = [
    // Data for Slides...
  
  ]

  activeSlides?: SlidesOutputData = new SlidesOutputData; 

  getData(data: SlidesOutputData) {
   
    this.activeSlides = data;

    if (this.activeSlides && this.activeSlides.slides) {
      for (const slide of this["activeSlides"].slides) {
        if (slide.center === true) {
          console.log('Centralized Slide:', slide);

        }
      }
    }
  }

  @ViewChild('testimonialarticle')
  classArticle: ElementRef = new ElementRef('testimonialarticle');

  ngOnInit() {
    
    console.log(this.classArticle);

    this.renderer.selectRootElement('#testimonialarticle').setStyle(this, "background-color", "black");
  }


  constructor(private renderer: Renderer2) {
  }
}

Answer №1

My journey to achieving this involved utilizing two methods. The first method, which involved using ::ng-deep, is now considered deprecated. The second method entailed incorporating the

encapsulation: ViewEncapsulation.None,
parameter within my @Component decorator.

While these approaches have worked for me so far, I remain on the lookout for alternative solutions as neither of them seem to be ideal in the long run.

@Component({
  selector: 'app-row-clients',
  templateUrl: './row-clients.component.html',
  styleUrls: ['./row-clients.component.css'],
  encapsulation: ViewEncapsulation.None,
})

With encapsulation disabled, I am able to style my component as desired:

.testimonialcarousel .owl-item.active.center {
  opacity: 1;
  transform: scale3d(1.0, 1.0, 1);
}

Despite finding a way to style my component, I am still dissatisfied with not being able to implement a more secure and recommended approach.

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

Using TypeScript to assign values to object properties

In myInterfaces.ts, I have defined a class that I want to export: export class SettingsObj{ lang : string; size : number; } Now I need to reference this class in another file named myConfig.ts in order to type a property value for an object called CO ...

Is it possible to confirm the authenticity of a hashed secret without having knowledge of the salt used

My method of storing API-Keys involves hashing and saving them in a database. ... async function createToken(userId:number) { ... const salt=await bcrypt.genSalt(15) const hash=await bcrypt.hash(token, salt) await db.store({userId,hash}) } ...

The data type 'string[]' cannot be assigned to the data type 'listData[]'

I'm currently developing a flexible component that allows the list view to be utilized by different components. However, the challenge arises from the fact that each component has a different data format. In my project, I'm unable to use type any ...

What steps can be taken to initiate Nx Release on the apps/* when modifications are made to the connected libs/* modules?

Trying out the nx release command but struggling to get it to release an app when there are changes to a dependent module. Examining the graph below, you can see that I have 3 apps, with 2 depending on the shared-ui module. https://i.sstatic.net/QYDBlRnZ.p ...

I encountered an error in my Node.js application stating that it could not find the name 'Userdetailshistory' array. I am puzzled as to why this error is occurring and I suspect it may be due to my

import { Component, OnInit } from '@angular/core'; import { UserdetailshistoryService } from '../../services'; @Component({ selector: 'my-userdetailshistory', templateUrl: './userdetails-history.component.html', ...

What are the steps to successfully launch a Node.js / Express application with typescript on heroku?

I attempted to deploy my node.js / express server app on Heroku but encountered some issues. I followed the steps outlined in a blog post, which you can find here. Unfortunately, the deployment did not succeed. Below are snippets of the code from my serve ...

Accessing the various types within a monorepo from a sibling directory located below the root folder

Seeking assistance in resolving a referencing types issue within a TypeScript monorepo project. Unsure if it is feasible given the current setup. The project structure is as follows: . ├── tsconfig.json ├── lib/ │ └── workers/ │ ...

The value returned by UseSelector is not defined

this code snippet is responsible for monitoring the state of a shopping cart that contains various bets placed by the user const { games } = useSelector((state: any) => state.cart) which is then passed to another component like this <AppRecentUserG ...

Issue with the back button in Angular and Capacitor

Currently, I am utilizing the Capacitor plugin alongside Angular 8. However, I have encountered an issue where clicking on the back button in Android redirects me to the login page without triggering the backButton listener. App.addListener('backButto ...

Issue with Angular 5: Child component emitting event results in loss of focus on child form

I have a child component containing a form group with multiple form controls. I am utilizing the valueChanges function to determine the actions to take when a control is modified: this.proposalItemForm.get('qtyControl').valueChanges.forEach( ...

Ivy workspace encountered an error with Angular being undefined: <error>

Recently, I attempted to install Angular on my MacOS terminal by entering the command $ npm install -g @angular/cli Unfortunately, the installation kept failing and the terminal displayed an error message. Subsequently, I tried the command $ sudo npm inst ...

Designing a unique and customized theme for Angular 4

Exploring the world of Angular 4 and Angular Material is an exciting journey for me. Currently, I am delving into the creation of a custom theme in Angular 4. In order to achieve this, we make use of variables to assign colors to primary, accent, and warn ...

What are the steps to incorporating a personalized component into an extension?

I am working on a TypeScript file that includes a class inheriting cc.Component. My goal is to package this file as an extension and make it easily accessible within the editor, allowing users to add it to a node with ease. What steps should I take to ac ...

Angular - Render distinct options in dropdown depending on criteria

In the HTML code, I have a condition to display the value of data as a dropdown. Now, I want to introduce another condition where when a different dropdown menu with company names is changed (e.g. changing it to 'Amazon'), only the corresponding ...

Dealing with CORS and multiple headers

After setting up CORS for my web api project and deploying it to local IIS, I encountered an issue when trying to call a controller method from Angular. The error message displayed was as follows: SEC7128: Multiple Access-Control-Allow-Origin headers ar ...

Difficulty transferring information between two components by using services

I am trying to pass the values of an array from the Search component to the History component in order to display the search history. My current code structure looks like this: search-page.component.ts export class SearchPageComponent implements OnInit ...

Using Firestore queries in your NodeJS application

Here's a query that is functioning as intended: const queryRef = firestore.collection('playlists').where('machines', 'array-contains', id) const snapshot = await queryRef.get() ... const playlist = document.data() as Pl ...

Deleting a row from a table in Angular using a modal popup

Is there a way to remove a table row by pressing the confirm button in the modal popup? Open Delete Row Modal Popup I've attempted several methods without success thus far. I have coded separate components for adding, editing, and deleting users. H ...

How to incorporate a multi-dimensional object using ng-init in AngularJS

Trying to include a multi-dimensional object in ng-init: object({ friends:[ {name:John,phone:555-1276}, {name:Mary,phone:800-BIG-MARY}, {name:Mike,phone:555-4321}, {name:Adam,phone:555-5678}, {name:Julie,phone ...

Steps for creating a scrollable mat-list:1. Start by defining

Looking for a solution to create a scrollable mat-list within a responsive height container using Angular 4.4.6 and Angular Material 2.0.0-beta.12. How can I prevent the mat-list from overflowing the parent container? Check it out on stackblitz: https://s ...