Personalized Carousel using Ng-Bootstrap, showcasing image and description data fields

I have been working on customizing an Angular Bootstrap Carousel and have managed to successfully change the layout. I now have two columns - with the image on the right and text along with custom arrows on the left.

My goal is twofold: First, I am looking for a more efficient way to list the images. Currently, the list of images is in my gallery.ts file, but as there will be many more images in the future, I was thinking about storing this information in a separate file and retrieving it from there. Is that possible?

Here is a snippet from my gallery.ts:

... // code removed for brevity

Secondly, I also need the text in the left column to change dynamically along with the image. Each slide should display a date and a brief description. Any suggestions on how to achieve this?

Here is an excerpt from my gallery.html:

... // code removed for brevity

Answer №1

Here are the key points from your query:

  • Is there a way to store the information in a separate file and retrieve it from there?

    • Yes, you can store this data in a JSON file on your server or in a database; in my example, I used a JSON file.
  • I need to dynamically change the text on the left column along with the image for each slide, displaying a date and brief description.

    • You can use an object instead of an array of images, including all the necessary fields for your frontend.

relevant JSON file:

{ "imgArray": [
{"img": "https://picsum.photos/id/501/900/500", "heading" :"first", "description":"first heading's description"},
{"img": "https://picsum.photos/id/502/900/500", "heading" :"h2", "description":"second heading's description"},
{"img": "https://picsum.photos/id/503/900/500", "heading" :"h3", "description":"third heading's description"},
{"img": "https://picsum.photos/id/504/900/500", "heading" :"h4", "description":"fourth heading's description"},
{"img": "https://picsum.photos/id/505/900/500", "heading" :"h5", "description":"fifth heading's description"},
{"img": "https://picsum.photos/id/506/900/500", "heading" :"h6", "description":"sixth heading's description"},
{"img": "https://picsum.photos/id/507/900/500", "heading" :"h7", "description":"seventh heading's description"}
]
}

relevant HTML:

<ngb-carousel *ngIf="images">
    <ng-template ngbSlide *ngFor="let slide of images; index as i">
        <div class='row'>
            <div class='col-lg-6 col-md-6 col-sm-6 col-6 '>
                <div class="description_date">
                    <h1>{{slide.heading}}</h1>
                </div>
                <div class="description_text">
                    {{slide.description}}
                </div>
            </div>
            <div class='col-lg-6 col-md-6 col-sm-6 col-6'>
                <div class="gallery_img">
                    <figure>
                        <img [src]="slide.img" alt="Random first slide">
          </figure>
        </div>
      </div>
    </div>
    </ng-template>
</ngb-carousel>

relevant TS:

import { Component } from '@angular/core';
import { NgbCarouselConfig } from '@ng-bootstrap/ng-bootstrap';
import * as dataJSON from './data.json';

@Component({
  selector: 'ngbd-carousel-config',
  templateUrl: './carousel-config.html',
  providers: [NgbCarouselConfig]  
  ,styles: [` 
  .img-fluid{ min-width:100%}
  .row{background:lightgray;}
  .description_date, .description_text { padding:5%; }
  `]
})
export class NgbdCarouselConfig {
  images:any[] = []
  readJSON = dataJSON;

    constructor(config: NgbCarouselConfig) {
        config.interval = 10000;
        config.wrap = false;
        config.keyboard = true;
        config.pauseOnHover = false;

        this.images = this.readJSON.default.imgArray;
    }
}

working example here

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

Exploring the concept of union return types in TypeScript

Hello, I am facing an issue while trying to incorporate TypeScript in a way that may not be its intended use. I have created a custom hook called useGet in React which can return one of the following types: type Response<T> = [T, false, false] | [nul ...

Angular 2 Update RC5: Router Provider Not Found

I'm encountering an issue with the latest Angular 2 RC5 router (router version is RC1). Below is the error log from the dev console: EXCEPTION: Error in /templates/app.component.html:2:0 ORIGINAL EXCEPTION: No provider for Router! This is how my ap ...

Images are not appearing correctly on Chrome browsers when using Windows operating system

img tags seem to have unusual margins in Chrome, Edge, and Opera browsers, while Firefox displays them correctly. Queries What is causing these margins specifically in Chrome? The Devtool does not detect any margin properties. Is there a straightforward s ...

Executing a Prisma query with a selection

My Prisma models involve User, Car, and Reservation entities: model User { id String @id @default(auto()) @map("_id") @db.ObjectId name String? email String? @unique emailVerified DateTime? image ...

Please provide an explanation for the statement "document.styleSheets[0].cssRules[0].style;"

I'm seeking an explanation for this block of code: document.styleSheets[0].cssRules[0].style; It would be helpful if you could use the following code as a reference: * { padding: 0; margin: 0; box-sizing: border-box; font-family:&apos ...

How come modifying the css of one component impacts all the other components?

Issue: I am struggling to make CSS changes only affect the specific component I want, without impacting other elements on the page. My goal is to style my dropdown menu without affecting other text input fields: Background/Challenge: While I understand wh ...

Utilizing Angular 2 alongside ngrx/store for seamless updates to specific properties within the state object without disrupting the entire structure

I am facing an issue where I need to update a property of a state object without creating a new object. Is there a way to add or update a single property without replacing the entire object? Below is the reducer code: const initialState = { all: [], ...

What can be done to prevent divs from overlapping? They display properly on a computer browser, but not on mobile devices like phones or tablets

Recently, I took on the task of creating an eBay template for someone. With some assistance and a bit of trial and error, I managed to get it working, albeit with what I like to call "not-so-great" code. However, there is one issue that arises when viewing ...

Encountering a Vueify Typescript error in a Vue project

Recently diving into the world of Vue, I was able to successfully create a sample app using gulp, vueify, and TypeScript. To showcase what's happening and shed light on an issue I'm facing, here are snippets of the key code segments: Menu.ts im ...

Best Practices for Architecture and Routing in Angular 8 (suggestions)

As a newcomer to Angular, I find myself grappling with the recommended architecture for my project. In an effort to streamline my inquiry, I will structure it in the form of choosing between options A or B and exploring how to implement that choice. Specif ...

Questioning the syntax of a TypeScript feature as outlined in the documentation

I have been studying the Typescript advanced types documentation, available at this link. Within the documentation, there is an example provided: interface Map<T> { [key: string]: T; } I grasp the concept of the type variable T in Map. However ...

An issue arises when trying to utilize meta tags in Nuxtjs while incorporating TypeScript into the

When working with Nuxtjs, I encountered an issue regarding my permissionKeys on the page and checking user access in the middleware. Everything runs smoothly when my script language is set to js, but errors arise when set to lang="ts". I tried to find a s ...

Why isn't the background-image displaying with the use of the url() function?

I've been attempting to set an image as the background using background-img:url(imageLing), but it's not working properly. When I inspect the element, it shows me background-image: url(assets/backgrounds/5.jpg);. What could be causing this issue? ...

Updating image content on the fly in a popover

Here is my unique HTML code: <div class="col-12 custom-file" data-toggle="popover-hover"> <input type="file" id="fileUpload" class="custom-file-input" accept=".jpg,.png,.jpeg"> < ...

The click interactions of SVG elements are altered when switching between <img> and <object> elements

I currently have 4 SVG buttons featured in the main menu of my personal website. https://i.stack.imgur.com/gA7En.png /----------------------------------------------------------------------------------------------------------------------------------/ Upo ...

Issue with the text wrapping of Angular mat-list-option items

When the text of my checkboxes is too long, it doesn't wrap properly. Please see the image below for reference: Click here to view Checkbox image and check the red box Here is my HTML code: <mat-selection-list #rolesSelection ...

Cannot access assets: Angular 8 deployment on Tomcat 9.0.30 is prevented due to an invalid MIME type ("text/html")

I am currently working on a project that involves an angular 8 user interface and a springboot java backend. The project is structured as a multi module project, with the angular portion in a separate module. To build the angular code into a single executa ...

The arrangement of elements in an inline-block is determined by the width of the section

I have been attempting to replicate the layout shown in the image for quite some time. The elements (.element) are aligned vertically but they are not centered, instead they stick to the left side. My current code is as follows: HTML: <div id="_tec ...

Troubleshooting a Problem with the Horizontal Scrollbar in Dynamic jqGrid

Currently, I am working on an ASP.net MVC project where I have implemented both dynamic and static jq grids. However, I am encountering an issue with the horizontal scroll bar in my application. To address this problem, I attempted to modify the overflow ...

The background color feature of a div is malfunctioning

I have encountered a strange issue with one of my Div elements. When I add text inside the div, the background color sticks to the text. However, if there is no text present, the background color disappears. Image with Text: https://i.stack.imgur.com/oYK ...